VMware Power CLI Useful Scripts
1. Collect OS information for all the Guest in a V Center.
Get-VM | Select Name,PowerState, @{N="GuestOS";E={($_ | Get-VMGuest).OSFullName}} | Export-Csv -NoTypeInformation -Path "Report.csv"
2. Collect Basic IP Address information for all the Guest in a V Center.
get-vm | select Name,@{N="IP Address";E={@($_.guest.IPAddress[0])}} | out-file ip.txt
3. Find Server Name, Host and CPU information for the Guest OS.
Get-VM | Select-Object Name, VMHost, NumCpu
4. Collect Inventory
@========OS INFO of VM===============================================
foreach ($vmView in (Get-View -ViewType VirtualMachine))
{
$report += $vmView | Select-Object @{Name="VMHost"; Expression={(Get-View $vmView.Runtime.Host).Name}},
@{Name="VMName"; Expression={$_.Name}},
@{Name="GuestVersion"; Expression={$vmView.Guest.GuestFullName}}
}
$report | Sort-Object VMName -Descending | Export-Csv "vm_GuestVersion.csv" -NoTypeInformation
========================================================================
5. List all ESX host MAC addresses.
get-vmhost | get-vmhostnetworkadapter | export-csv d:\temp\VMHost.csv
6. List all guest VM MAC addresses
get-vm | get-networkadapter | export-csv d:\temp\VMAdapter.csv
7. Collect Snapshot information's.
Get-VM | Get-Snapshot | Select-Object -Property Name, Description, Created, SizeGB | Format-List *
8. Script Signing.
Get-executionpolicy
Set-ExecutionPolicy AllSigned
Set-executionpolicy unrestricted
Set-executionpolicy remotesigned
9. Connect V-Center using power CLI
Connect-VIServer
10. Disconnect V-Center
Disconnect-VIServer -Server
11. Get the VM data with Snapshot, Datastore, Total Disk Size, Cluster Name, OS Name
# To Get the VM data with Snapshot, Datastore, Total Disk Size, Cluster Name, OS Name Set-ExecutionPolicy Remotesigned -force if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) { Add-PSSnapin VMware.VimAutomation.Core} $VC1 = read-host "Type the VC name" $date = Get-Date -DisplayHint DateTime -Format "yyyy-M-d" Connect-VIServer -Server $VC1 -WarningAction SilentlyContinue Get-VM | Select Name,PowerState, @{N="SnapName";E={ ($_ | Get-Snapshot).Name}},@{N="Datastore";E={ ($_ | Get-Datastore).Name}},@{ N="TotalDisk"; E={ ($_ | Get-harddisk | measure-object -property CapacityKB -sum).Sum}},@{N="GuestOS";E={ ($_ | Get-VMGuest).OSFullName}},@{N="Cluster";E={ ($_ | Get-Cluster).Name}}| Export-Csv -NoTypeInformation -Path \\xyz\Reports\Report-$VC1-$Date.csv Disconnect-VIServer -server $VC1 -Force -Confirm:$false
No comments:
Post a Comment