Always A-HEAD, By being ahead you are always master of time

Hits

BOOKS

Sunday, February 11, 2007

Daily logs of DiskSize

I truly believe in learning new things and try out new things. Even there could be more than one way of doing it, it makes me crazy to put old things in new way, because you never new that it could be done in this way.

$Cusdate=(get-date).tostring("ddMMyyyy")
$file=new-item -type file "$Cusdate-freedisk.txt"
get-content "E:\PowerShell\Outputfiles&Folders\servers.txt" | % {

if((get-wmiobject win32_pingstatus -Filter "address='$_'").protocoladdress) {
$wmiObj=gwmi win32_logicaldisk -filter "deviceid='c:'" -computer $_
$freesp="{0:N02}" -f ($wmiObj.freespace/1MB)
$Totalsp="{0:N02}" -f ($wmiObj.size/1MB)
add-content $file "Total Size on C Drive of $_ : $Totalsp (MB)"
add-content $file "Free Size on C Drive of $_ : $Freesp (MB)"
}

else {
write-host $_ is not reachable -foreground "RED"
$Doubleline = ("="* 60)
add-content $file $Doubleline
add-content $file "$_ is not reachable"
}
}

http://thepowershellguy.com/blogs/posh/archive/2007/02/08/sesame-powershell-scripting-text-files.aspx

Above link is where the original code and Idea resides. I've modified it little but to look more like PowerShell.

Output is:

 

 

 

 

 

 

New things learnt:

$Cusdate=(get-date).tostring("ddMMyyyy") you can customize the date format.

Below is single line which will check if server is online, cause it makes sense before you do anything on the server, to make sure it is live.

if((get-wmiobject win32_pingstatus -Filter "address='$_'").protocoladdress) this will return true if server is live.

 

IceRocket tags: , ,

del.icio.us tags: , ,

Technorati tags: , ,

No comments: