Monday, May 6, 2013

Using Powershell at logon to show you the VHOST and VM status... Brief detail

This has now been added to a free powershell hyper-v manager project.

Ok create  welcome.ps1 file that contains
# Variables
$DateStamp = get-date -uformat "%m-%d-%Y"
$computers = $Env:COMPUTERNAME
$VMS = get-vm
$file = "C:\software\reports\welcome.txt"

# Display a welcome message
echo "Log On Welcome Report" | out-file $file
get-date | out-file $file -append
# get the vhost uptime
Get-CimInstance Win32_OperatingSystem -comp $computers | Select @{Name="VHostName";Expression={$_."csname"}},@{Name="Uptime=D.H:M:S.Millseconds";Expression={(Get-Date) - $_.LastBootUpTime}},LastBootUpTime | format-table -autosize | out-file $file -append

echo "VHOST Server drive C: Disk Space" | out-file $file -append
# to get D: drive add ,D after C  - E: drive ,E etc.
Get-psdrive C | Select Root,@{N="Total(GB)";E={""+ [math]::round(($$_.used)/1GB)}},@{N="Used(GB)";E={""+ [math]::round($_.used/1GB)}},@{N="Free(GB)";E={""+ [math]::round($}} |format-table -autosize | out-file $file -append

echo "Total number of VM's on server" | out-file $file -append
echo "------------------------------" | out-file $file -append
$VMS.Count | out-file $file -append
echo " " | out-file $file -append

write-host Current virtual machine status: | out-file $file -append
get-vm | out-file $file -append

notepad.exe "C:\software\reports\Welcome.txt"

Now create a welcome.bat that contains
call powershell C:\software\welcome.ps1

Now edit the your registry:

Whenever you log onto the vhost you will get a brief report of the vhost and vm's like this in notepad.

Log On Welcome Report

Friday, May 31, 2013 4:45:12 PM

VHostName Uptime=D.H:M:S.Millseconds LastBootUpTime      
--------- -------------------------- --------------      
VHOST1    -18:57:23.6969442          6/1/2013 11:42:36 AM

VHOST Server drive C: Disk Space
Root Total(GB) Used(GB) Free(GB)
---- --------- -------- --------
C:\  408       25       383     

Total number of VM's on server

Name  State   CPUUsage(%) MemoryAssigned(M) Uptime   Status            
----  -----   ----------- ----------------- ------   ------            

test1 Running 0           4096              00:45:27 Operating normally

No comments:

Post a Comment