EDIT: QUESTION HAS BEEN ANSWERED SEE THE BOTTOM OF MY POST FOR MY FINAL SCRIPT...
Man, I'm a powershell noob...
I have this link:
http://gallery.technet.microsoft.com/ScriptCenter/en-us/da3fee00-e79d-482b-91f2-7c729c38068f
I'd like to use that to take a list of servers, run it against that list, and then get a report of each server with disk space similar to:
SERVER1
C: Total=120GB Free Space=60GB D: Total=400GB Free Space=200GB
etc.
The problem is...
I don't know what to do with the script on that link to get it to work. Copy/paste it into notepad and save as a .ps1?? Doesn't seem to be that way in the description.
Will it work if I run it from my Win7 box with PS, or does every server have to have Powershell installed for a remote PS script to work?
Is there a way to setup the script to email me? That way I can set it as a weekly task or similar.
Thank you!
========
Final script
function Get-FreeDisk
{
[CmdletBinding()]
param(
[Parameter(Position=0, ValueFromPipeline=$true)]
[string[]]$Computername="localhost",
[int]
[ValidateRange(0,100)]
$MinPercFree = 100,
[Management.Automation.PSCredential]$Credential = ([Management.Automation.PSCredential]::Empty)
)
begin{
[String[]]$computers = @()
}
process{
$computers += $Computername
}
end{
Get-WmiObject -computername $computers -Credential $Credential `
-Query "select __SERVER, Caption,Label,Capacity,FreeSpace from Win32_Volume where DriveType != 5 and Capacity > 0" | `
Add-Member -Name Free -MemberType ScriptProperty -PassThru -Value {($this.FreeSpace/10000) / ($this.Capacity/1000000)} | `
Where { $_.Free -lt $MinPercFree } | `
sort __SERVER,Caption | `
Format-Table @{Label="Computer"; Expression={$_.__SERVER}}, Caption, Label,`
@{Label="Size/MB"; FormatString="{0,7:N0}"; Expression={$_.Capacity / 1mb}},`
@{Label="FreeSpace/MB"; FormatString="{0,7:N0}"; Expression={$_.Freespace / 1mb}}, `
@{Label="Free"; FormatString="{0,3:N0}%"; Expression={$_.Free}} -AutoSize
}
}
Get-Content .\servers.txt | Get-FreeDisk | Format-Table -AutoSize | Out-File diskusage.txt
Send-MailMessage -To [email protected] -Subject "Server Disk Report" -From [email protected] -SmtpServer mail.domain.com -Attachments "diskusage.txt"