Powershell function to Check disk free space on remote computers

Description:

This function takes the computer name as argument and displays the disk free/total size information. One advantage with this function is, no need to search for admin windows when you want to run it. It prompts for admin credentials and connects to remote computer using them.

Usage:

PS C:\temp> Check-Diskspace -computer remotepc
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Drive Name :  C:

Total Space :  232.83 GB

Free Space :  0.94 GB

PS C:\temp>

Code:

function Check-Diskspace {

param (

[parameter(Mandatory = $true)]

[string]$computer

)

$cred = Get-Credential

$drives = gwmi -class Win32_LogicalDisk -computer $computer -credential $cred | where { $_.DriveType -eq 3 }

foreach ($drive in $drives) {

    write-host “Drive Name : ” $drive.DeviceID

    write-host “Total Space : “($drive.size/1GB).ToString(“0.00″) “GB”

    write-host “Free Space : ” ($drive.FreeSpace/1GB).ToString(“0.00″) “GB”

    write-host “”

}

$cred = $null

}

Tags:

Leave a Comment

Get computer uptime using Powershell

Simple Way to get local computer uptime….

PS C:\> (gwmi win32_operatingSystem).lastbootuptime
20100728180723.375199+330
PS C:\>

Now, let’s query the remote computers uptime.

PS C:\> (gwmi win32_operatingSystem -computer remotePC).lastbootuptime
20100728180723.375199+330
PS C:\>

The above are oneliners, if you want to convert this into full fledged function, use the below code. This gives the uptime of computer you have parsed.

C:\>Get-PCuptime -computer remotePC

System(remotePC) is Uptime since :  14 days 20 hours 54 minutes 20 seconds

C:\>

Code for function:

function Get-PCUptime {

param($computer)

$lastboottime = (Get-WmiObject -Class Win32_OperatingSystem -computername $computer).LastBootUpTime

$sysuptime = (Get-Date) – [System.Management.ManagementDateTimeconverter]::ToDateTime($lastboottime)

Write-Host“System($computer) is Uptime since : ” $sysuptime.days “days” $sysuptime.hours `

“hours” $sysuptime.minutes “minutes” $sysuptime.seconds “seconds”

}

Tags:

Leave a Comment

Utility to change password in Services/Scheduled tasks on remote Servers

Changing the password is one of the regular activities for a typical System Administrator. It is not an easy task unless you have required tools in your tool kit. If you have changed one of your domain admin password, you need to find the places(be it services or scheduled tasks) where you have saved it and update password there. If you have 1000 servers, then you will endup updating/scanning remote server’s services/scheduled tasks one after another unless you have some home grown scripts to serve this purpose. 

Well, I have some good news if you are still spending long hours to change the passwords. Today I came across a new utility called SSTUM (Service and Scheduled Task User Manager) which helps you in changing the password in remote services or scheduled Tasks with less efforts.

A few things I notices about this tool are…

1) Easy to use and saves lot of time
2) Input can be a computer list or you can make selection from active directory
3) Has an option to restart service after changing the password — pretty useful
4) Support exporting of results to some text file
 5) Supports changing the username as well.

More details about this tool and download location are available at http://martin77s.wordpress.com/2010/07/19/service-and-scheduled-task-user-manager/

Hope this definitely helps.

Tags: , ,

Leave a Comment