I am writing a small script that finds all computer objects in ad that have a certain OS. It all seems to run fine, but I get no results back. I have a sneaking suspision that my variable is not being called into the comparison filter. It that actually possible?
The script is as follows:
Import-Module ActiveDirectory Write-Host "" Write-Host "" [int]$OSChoice = 0 while ( $OSChoice -lt 1 -or $OSChoice -gt 7 ){ Write-host "1. Windows XP" Write-host "2. Windows Vista" Write-host "3. Windows 7" Write-host "4. Server 2003" Write-host "5. Server 2008" Write-host "6. Server 2012" Write-host "7. Quit and exit" [Int]$OSChoice = read-host "Please choose an operating system with 1 to 7..." } Switch( $OSChoice ){ 1{$OS = "Windows XP"} 2{$OS = "Windows Vista"} 3{$OS = "Windows 7"} 4{$OS = "Server 2003"} 5{$OS = "Server 2008"} 6{$OS = "Server 2012"} 7{break} default{$OS = "Windows XP"} } Write-Host "" Write-Host "You chose the operating system: $OS" Get-ADComputer -Filter {OperatingSystem -like "*$OS*"} -Properties Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion | Format-Table Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion -Wrap -Auto