To use ‘Connect-VIServer’ cmdlet in your PowerShell script. You have to follow two steps: 1) Install VMware PowerCLI in your machine. It will register itself in PowerShell during the installation. 2) Use ‘Add-PSSnapIn VMware.VimAutomation.Core’ to add the registered PowerShell VMware Snapin to the current session.
Tag: PowerShell
Moving VM to Folder in vCenter
To make things more organized in vCenter, I use folders to categorize the servers with the same functions together. The folders can be Production with subfolders SQL server, Linux server … But somehow, two servers refused to move. Everything looks fine, they just did not want to move to a new folder. After being frustrated … Continue reading Moving VM to Folder in vCenter
PowerShell: List the Hyper-V VM VHD Location
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
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