asked on
ASKER
ASKER
#Clear-Content "E:\Scripts\Powershell\TEST\Output\ServerNames_all.txt
#OS Level search in AD
$strCategory = "computer"
$strOS1 = "Windows Server 2003"
$strOS = "Windows Server 2000"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = "(&(objectCategory=$strCategory)(|(operatingSystem=$strOS1)(operatingSystem=$strOS)))"
$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{$objComputer = $objResult.Properties; $objComputer.name}
ASKER
ASKER
Function Get-Utilization {
Param([string]$computername=$env:computername,
[string]$ID="C:"
)
#suppress errors messages
$errorActionPreference="silentlycontinue"
$drive=Get-WmiObject Win32_Logicaldisk -filter "DeviceID='$ID'" `
-computername $computername -errorAction "silentlycontinue"
if ($drive.size) {
#divide size and freespace by 1MB because they are UInt64
#and I can't do anything with them in there native type
$size=$drive.size/1MB
$free=$drive.freespace/1MB
$utilization=($size-$free)/$size
$u=$utilization
}
else {
#there as an error so return a value that can't be mistaken
#for drive utilization
$u=-1
}
#Format $u as a percentage to 2 decimal points
$percent="{0:P2}" -f $u
if ($u -eq -1) {
$msg="WARNING: Failed to get drive {0} on {1}" -f $drive,$computer
$color="RED"
}
elseif ($u -ge .85){
$msg="WARNING: Drive {0} on {1} is at {2} utilization." -f $drive,$computer,$percent
$color="RED"
}
else {
$msg="WARNING: Drive {0} on {1} is at {2} utilization." -f $drive,$computer,$percent
$color="GREEN"
}
Write-Host $msg -foregroundcolor $color
}
#Server List
$ServerList = "E:\Scripts\PowerShell\Test\Output\ServerNames_all.csv"
Import-csv -path $ServerList |
foreach-object `
{
#Loops through all drives
$drives = get-wmiobject -class "Win32_LogicalDisk" -filter "DriveType= 3" `
-namespace "root\CIMV2" -computername $_.FQDN
foreach($drive in $drives){
Get-Utilization $computer $drive.DeviceID
}
}
ASKER
The Microsoft Legacy Operating System topic includes legacy versions of Microsoft operating systems prior to Windows 2000: All versions of MS-DOS and other versions developed for specific manufacturers and Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions, and Windows Mobile.
TRUSTED BY
I will try to post something later
FYI: Powershell Zone https://www.experts-exchange.com/Programming/Languages/Scripting/MSH-Monad/