Query List of VMs
The following PowerShell script will query VMM for a list of VMs. Use this as a start.
1 2 | Import-Module virtualmachinemanager; Get-VM -VMMServer vmm.servername01 | Format-List -property Name, Owner, Description, HostName, OperatingSystem, CPUCount, Memory |
Query List of VMs and Export as CSV
Filter the VM name for all APP servers and export the list to csv:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | Import-Module virtualmachinemanager; $MasterList = @(); $serverList = Get-VM -VMMServer vmm.servername01 | Where-Object { (($_.Name -like '*APP*' -or $_.Name -like '*WEB*' -or $_.Name -like '*CORP*' -or $_.Name -like '*UTIL*') -and $_.Name -notlike '*DEV*') }; foreach ($server in $serverList) { $serverNetworkAdapter = Get-SCVirtualNetworkAdapter -VM $server; $MyObject = New-Object PSObject -Property @{ ServerName = $server.Name; ServerEnvironment = $server.Name.Substring(3,4); HostName = $server.HostName; VMStatusString = [string]$server.StatusString; VMState = [string]$server.VirtualMachineState; ServerIPAddress = $serverNetworkAdapter.IPv4Addresses; CPUCount = $server.CPUCount; Memory = $server.Memory; OperatingSystem = $server.OperatingSystem; IsHighlyAvailable = $server.IsHighlyAvailable; Description = $server.Description.Replace([Environment]::NewLine, ''); CreationTime = $server.CreationTime; }; $MasterList += $MyObject; }; $MasterList | Select-Object @{label='Server Name';expression={$_.ServerName.ToUpper()}}, @{label='Environment';expression={$_.ServerEnvironment.ToUpper()}}, @{label='VM Status';expression={if ($_.VMStatusString -eq $_.VMState) { $_.VMStatusString } else { $_.VMState + ' (' + $_.VMStatusString + ')'}}}, @{label='Host Name';expression={$_.HostName.Replace('.company.com','').ToUpper()}},@{Name=’ServerIPAddress’;Expression={if ([string]::join(";", ($_.ServerIPAddress))) {[string]::join(";", ($_.ServerIPAddress))} else { " " }}},@{label='Cores';expression={$_.CPUCount}},@{label='Memory';expression={$_.Memory}},@{label='OS';expression={$_.OperatingSystem}},@{label='Highly Available';expression={$_.IsHighlyAvailable}},@{label='Comments';expression={if ($_.Description) {$_.Description + ', Created ' + $_.CreationTime} else { 'Created ' + $_.CreationTime }}} | EXPORT-CSV c:\temp\server-list.csv -notype; |