The following PS script is to query the VHD location of each VM running on the hosts listed in the C:\scripts\Hyperv_Hosts.txt file. cls cd "c:\Scripts" $HyperVParents = Get-Content Hyperv_Hosts.txt Foreach ($HyperVParent in $HyperVParents) { $VMManagementService = Get-WmiObject -class "Msvm_VirtualSystemManagementService" -namespace "root\virtualization" -ComputerName $HyperVParent $VMs = Get-WmiObject -Namespace "root\virtualization" -ComputerName $HyperVParent -Query "Select * From Msvm_ComputerSystem … Continue reading PowerShell: List the Hyper-V VM VHD Location
Category: Scripting
PowerShell: Hyper-V VM Inventory
Having a clean inventory of all virtual machines is a good practice to avoid virtual machine sprawl. I created a script to send me to the Monthly VM Inventory automatically, this includes the Guest name, status, OS, vCPU, RAM, host and notes. The results look like this: JC-VM-01STATUS: RunningVCPU: 1RAM: 2048 MOS: Windows Server 2008 … Continue reading PowerShell: Hyper-V VM Inventory
PowerShell: Monitor Hyper-V VM Heartbeat
$hostname = “ServerName” $service = gwmi -class "Msvm_VirtualSystemManagementService" -namespace "root\virtualization" -ComputerName $hostname $VM = gwmi -ComputerName $hostname -namespace "root\virtualization" -query "Select * from Msvm_ComputerSystem where Caption='Virtual Machine'" Foreach ($_ in $VM) { Write-Host $_.ElementName $settings = gwmi -ComputerName $hostname -namespace "root\virtualization" -query ("ASSOCIATORS OF {" + $_.__PATH + "} WHERE resultClass = Msvm_VirtualSystemsettingData") $HB = … Continue reading PowerShell: Monitor Hyper-V VM Heartbeat
PowerShell: Send Email
I scheduled a task to send me the every day report by Email. Here is how I did by using PowerShell: $emailFrom = Monitor@test.com$emailTo = jackie.chen@test.com $subject = "Everyday Report"$body = Get-Content C:\Logs\EverydayReport.txt $smtpServer = "SMTP.test.com"$smtp = new-object Net.Mail.SmtpClient($smtpServer)$smtp.Send($emailFrom, $emailTo, $subject, $body)
PowerShell: Send SMS Through Outlook
1) Find a public SMS provider and register an account, there are plenty on the Internet. I use http://www.smsglobal.com in this example, and it works perfect. 2) Install Outlook 2010 and PowerShell on the server. If you use Outlook 2003 or 2007, MOSA has to be installed. 3) Configure Outlook 2010, go to ‘New Item … Continue reading PowerShell: Send SMS Through Outlook