cosine83

Admin Mod Snippet

Sep 1st, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $baseAD = "OU=Computers,OU=Test,DC=domain,DC=com"
  2. $Date = Get-Date -format MM.dd.yyyy
  3.  
  4. $Comp = Read-Host "Please define a computer"
  5. $OU = Read-Host "Please define an OU"
  6. $askNoGPI = Read-Host "Are the computers under the No GP Inheritance OU? (y/n/blank)"
  7.  
  8. If($Comp -notlike $null) { Set-Variable -Name searchComp -Value "CN=$Comp," }
  9. ElseIf($Comp -eq "") { Set-Variable -Name searchComp -Value $null }
  10.  
  11. If($OU -notlike $null) { Set-Variable -Name searchOU -Value "OU=$OU," }
  12. ElseIf($OU -eq "") { Set-Variable -Name searchOU -Value $null }
  13.  
  14. If($askNoGPI -eq 'y') { Set-Variable -Name searchNoGPI -Value "OU=No GP Inheritance," }
  15.  
  16. If($Comp,$OU -notlike $null -xor "" -and $askNoGPI -like "y") { Set-Variable -Name search -Value "$searchComp + $searchOU + $searchNoGPI" }
  17. ElseIf($Comp,$OU -notlike $null -xor "" -and $askNoGPI -like "n") { Set-Variable -Name search -Value "$searchComp + $searchOU - $searchNoGPI" }
  18. ElseIf($Comp,$OU -notlike $null -xor "" -and $askNoGPI -like "") { Set-Variable -Name search -Value "$searchComp + $searchOU - $searchNoGPI" }
  19. ElseIf($OU -notlike $null -xor "" -and $askNoGPI -like "y") { Set-Variable -Name search -Value "$searchOU + $searchNoGPI" }
  20. ElseIf($OU -notlike $null -xor "" -and $askNoGPI -like "n") { Set-Variable -Name search -Value "$searchOU - $searchComp" }
  21. ElseIf($OU -notlike $null -xor "" -and $askNoGPI -like "") { Set-Variable -Name search -Value "$searchOU - $searchComp" }
  22. ElseIf($Comp,$OU -eq "" -and $askNoGPI -like "y") { Set-Variable -Name search -Value "$searchNoGPI" }
  23. ElseIf($Comp,$OU -eq "" -and $askNoGPI -like "n") { Set-Variable -Name search -Value $null }
  24. ElseIf($Comp,$OU -eq "" -and $askNoGPI -like "") { Set-Variable -Name search -Value $null }
  25. Else { Set-Variable -Name search -Value $null }
  26.  
  27. If($search -notlike $null -xor "") {
  28. Set-Variable searchbase -Value "$search + $baseAD"
  29. }
  30. Else {
  31. Remove-Variable search
  32. Set-Variable searchbase -Value "$baseAD"
  33. }
  34.  
  35. $query = Get-ADComputer -Filter * -SearchBase $searchbase | Select Name | Sort Name
Advertisement
Add Comment
Please, Sign In to add comment