Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $baseAD = "OU=Computers,OU=Test,DC=domain,DC=com"
- $Date = Get-Date -format MM.dd.yyyy
- $Comp = Read-Host "Please define a computer"
- $OU = Read-Host "Please define an OU"
- $askNoGPI = Read-Host "Are the computers under the No GP Inheritance OU? (y/n/blank)"
- If($Comp -notlike $null) { Set-Variable -Name searchComp -Value "CN=$Comp," }
- ElseIf($Comp -eq "") { Set-Variable -Name searchComp -Value $null }
- If($OU -notlike $null) { Set-Variable -Name searchOU -Value "OU=$OU," }
- ElseIf($OU -eq "") { Set-Variable -Name searchOU -Value $null }
- If($askNoGPI -eq 'y') { Set-Variable -Name searchNoGPI -Value "OU=No GP Inheritance," }
- If($Comp,$OU -notlike $null -xor "" -and $askNoGPI -like "y") { Set-Variable -Name search -Value "$searchComp + $searchOU + $searchNoGPI" }
- ElseIf($Comp,$OU -notlike $null -xor "" -and $askNoGPI -like "n") { Set-Variable -Name search -Value "$searchComp + $searchOU - $searchNoGPI" }
- ElseIf($Comp,$OU -notlike $null -xor "" -and $askNoGPI -like "") { Set-Variable -Name search -Value "$searchComp + $searchOU - $searchNoGPI" }
- ElseIf($OU -notlike $null -xor "" -and $askNoGPI -like "y") { Set-Variable -Name search -Value "$searchOU + $searchNoGPI" }
- ElseIf($OU -notlike $null -xor "" -and $askNoGPI -like "n") { Set-Variable -Name search -Value "$searchOU - $searchComp" }
- ElseIf($OU -notlike $null -xor "" -and $askNoGPI -like "") { Set-Variable -Name search -Value "$searchOU - $searchComp" }
- ElseIf($Comp,$OU -eq "" -and $askNoGPI -like "y") { Set-Variable -Name search -Value "$searchNoGPI" }
- ElseIf($Comp,$OU -eq "" -and $askNoGPI -like "n") { Set-Variable -Name search -Value $null }
- ElseIf($Comp,$OU -eq "" -and $askNoGPI -like "") { Set-Variable -Name search -Value $null }
- Else { Set-Variable -Name search -Value $null }
- If($search -notlike $null -xor "") {
- Set-Variable searchbase -Value "$search + $baseAD"
- }
- Else {
- Remove-Variable search
- Set-Variable searchbase -Value "$baseAD"
- }
- $query = Get-ADComputer -Filter * -SearchBase $searchbase | Select Name | Sort Name
Advertisement
Add Comment
Please, Sign In to add comment