SteelMike
asked on
Monitoring Server Hard space
I am a complete newbie when it comes to scripting so please bare with me!!
I have around 300+ servers to include Virtual Machines that I need to monitor their physical Hard Drive space. Most of the servers and VM's will have two physical Hard drives (C: and D: respectfully).
First part of the script:
I need a script that will search active directory for computers that have either Win2000 or Win2003 and than export that list to a .csv file. I have other processes that could use this file.
Second Part:
Use the .csv file to find general information about the servers (CPU, Memory, # of HD's, HD Space, HD Free Space).
Thrid Part:
If any of the physical Hard Drive on a single server falls below lets say 5% they are added to a list of other servers meeting the same requirements.
Fourth Part:
Sends an email with the list of servers that fall below the 5%.
I don't have a lot of time to implement this script, so I need something that I can just copy from here, make a few minor changes and than push it out. I would prefer the script to be in Powershell, but at this point I really don't care. I just need some help!!
I have around 300+ servers to include Virtual Machines that I need to monitor their physical Hard Drive space. Most of the servers and VM's will have two physical Hard drives (C: and D: respectfully).
First part of the script:
I need a script that will search active directory for computers that have either Win2000 or Win2003 and than export that list to a .csv file. I have other processes that could use this file.
Second Part:
Use the .csv file to find general information about the servers (CPU, Memory, # of HD's, HD Space, HD Free Space).
Thrid Part:
If any of the physical Hard Drive on a single server falls below lets say 5% they are added to a list of other servers meeting the same requirements.
Fourth Part:
Sends an email with the list of servers that fall below the 5%.
I don't have a lot of time to implement this script, so I need something that I can just copy from here, make a few minor changes and than push it out. I would prefer the script to be in Powershell, but at this point I really don't care. I just need some help!!
ASKER
I will run through the first examples you gave now! Thank you.
ASKER
So I am pulling different items from the examples you provided and this is where I am so far. I'm learning so please be patient with me.
So I am able to pull a list of servers that have WIN2k and WIN2003, but I don't know what i need to do to pipe the results to a .csv file. I will add more points for the added help!
So I am able to pull a list of servers that have WIN2k and WIN2003, but I don't know what i need to do to pipe the results to a .csv file. I will add more points for the added help!
#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 CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help... I am working on getting the other parts up and running. Give me a day with testing and I should have something for you to look at.
ASKER
So I was able to search for the servers using the script above. I ran through the second part of the where it finds all logical disk=3. This is what I want the script to do. But the script was reading the servers from a text file instead of the .csv file. So as you can see I am having issues make the below script to read from the .csv file instead of a text file. Can you check through it for me and let me know where I went wrong!! Thank you
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
}
}
Open the CSV and see what the header row is. I bet it is not FQDN
ASKER
Thank you for the help. Even though it's a partial solution I am satisfied with the help you have provided.
I will try to post something later
FYI: Powershell Zone https://www.experts-exchange.com/Programming/Languages/Scripting/MSH-Monad/