Here i'm sharing one of the PowerCli script for Inventorying Redhat VMs in my VM environment. use connect-viserver with vcenter and then run this script.
if ( $args.length -ne 1)
{
echo "Usage: .\rhelinventory.ps1 [filename.csv]"
echo "Example: .\rhelinventory.ps1 report101.csv"
exit
}
$table = New-Object system.Data.DataTable "Results"
$col1 = New-Object system.Data.DataColumn Name,([string])
$col2 = New-Object system.Data.DataColumn OS,([string])
$col3 = New-Object system.Data.DataColumn Cluster,([string])
$table.columns.add($col1)
$table.columns.add($col2)
$table.columns.add($col3)
Get-View -ViewType VirtualMachine -Property Config.GuestFullName -Filter @{"Config.Template" = "false";"Config.GuestId"="rhel*"}| Select-Object @{n="ConfigdGuestFullName"; e={$_.Config.GuestFullName}} | Group-Object -NoElement ConfigdGuestFullName | Sort-Object Name | Format-Table -AutoSize
"Be Patient While Script is running.."
$vms=Get-View -ViewType VirtualMachine -Property Name, Config.GuestId -Filter @{"Config.Template" = "false" ; "Config.GuestId" = "rhel*"}|Select Name, @{n="ConfigdGuestId"; e={$_.Config.GuestId}}
foreach ($vm in $vms)
{
$row = $table.NewRow()
$row.Name = $vm.Name
$row.OS = $vm.ConfigdGuestId
$row.Cluster= (Get-Cluster -vm $vm.Name)
$table.Rows.Add($row)
}
$table | Format-Table
$table | Export-Csv -path $args[0]
if ( $args.length -ne 1)
{
echo "Usage: .\rhelinventory.ps1 [filename.csv]"
echo "Example: .\rhelinventory.ps1 report101.csv"
exit
}
$table = New-Object system.Data.DataTable "Results"
$col1 = New-Object system.Data.DataColumn Name,([string])
$col2 = New-Object system.Data.DataColumn OS,([string])
$col3 = New-Object system.Data.DataColumn Cluster,([string])
$table.columns.add($col1)
$table.columns.add($col2)
$table.columns.add($col3)
Get-View -ViewType VirtualMachine -Property Config.GuestFullName -Filter @{"Config.Template" = "false";"Config.GuestId"="rhel*"}| Select-Object @{n="ConfigdGuestFullName"; e={$_.Config.GuestFullName}} | Group-Object -NoElement ConfigdGuestFullName | Sort-Object Name | Format-Table -AutoSize
"Be Patient While Script is running.."
$vms=Get-View -ViewType VirtualMachine -Property Name, Config.GuestId -Filter @{"Config.Template" = "false" ; "Config.GuestId" = "rhel*"}|Select Name, @{n="ConfigdGuestId"; e={$_.Config.GuestId}}
foreach ($vm in $vms)
{
$row = $table.NewRow()
$row.Name = $vm.Name
$row.OS = $vm.ConfigdGuestId
$row.Cluster= (Get-Cluster -vm $vm.Name)
$table.Rows.Add($row)
}
$table | Format-Table
$table | Export-Csv -path $args[0]
Be Social.
No comments:
Post a Comment