I have a script to pull disk statistics from servers. I have it written to feed a variable like this and the script runs great:
$computers = get-adcomputer -filter * -searchbase "ou=servers,dc=domain,dc=local"
I'd like to change it to filter on operating system but when I do this, I get RPC server unavailable error, meaning when i send the variable to the next step it doesn't have the information.
$computers = get-adcomputer -filter {operatingsystem -like "windows server*"} -properties operatingsystem
Any idea why this happens, or how I can get the filtered server objects into the variable? Both statements run fine and feed results in the same format when run alone...
Full script here:
<#
.Synopsis
Gets disk space statistics from adcomputer
.DESCRIPTION
Uses OU to define what machines to look at, pulls disk statistics. Returns a txt file with results.
.EXAMPLE
Modify searchbase in script to control what you look at.
#>
$report = @()
# $computers = get-adcomputer -filter * -searchbase "ou=servers,dc=domain,dc=local"
#or
$computers = get-adcomputer -filter {operatingsystem -like "windows server*"} -properties operatingsystem
foreach ($computer in $computers) {
$report += "`n"
$report += $computer.DNSHostName + "`n"
$drives=Get-WmiObject Win32_LogicalDisk -ComputerName $computer.dnshostname
foreach ($drive in $drives){
$drivename=$drive.DeviceID
$freespace=[int]($drive.FreeSpace/1GB)
$totalspace=[int]($drive.Size/1GB)
$usedspace=$totalspace - $freespace
$pctused=if ($totalspace -eq 0) {0} else {[decimal](($usedspace/$totalspace)*100)}
$report +=$output+$drivename+"`t`t"+$usedspace+"`t`t`t"+$freespace+ "`t`t`t" +$totalspace+ "`t`t`t" +$pctused+ "`n"
}
}
$Report = $report | Out-String
$report | out-file c:\temp\diskspace_report.txt
Jim Tall