Template and Powered OFF VM’s Report from vCenter server
This powershell script will help you to pull report of powered off VM’s and the old templates. You can run this script from your desktop directly or from your vCenter server. You need to provide vCenter server list as input. Script will ask for credentials during runtime and output will be stored in csv file.
$VCServers = Get-Content "C:\vclist.txt"
$vcUSERNAME = Read-Host 'Enter user name'
$vcPassword = Read-Host 'Enter password' -AsSecureString
$logincred = New-Object System.Management.Automation.PSCredential ($vcusername, $vcPassword)
$date = Get-Date -Format "yyyy_MM_dd_hh_mm"
#---------------------------- VC Report generation-------------------------------------------#
foreach ($VCServer in $VCServers) {
Write-Host -ForegroundColor DarkYellow "Working on $VCServer"
Connect-VIServer -Server $VCServer -Credential $logincred # -ErrorAction SilentlyContinue -WarningAction 0 | Out-Null
#----------------- Template Report -----------------#
$csvfile_template = "C:\VC_reports\$($VCServer + "_" +$date + "_" + "template.csv")"
Write-Host -ForegroundColor Yellow "File name - $csvfile_template"
Get-Template -Name spwdfvm* | Sort-Object |
Select Name,
@{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}} |
Export-Csv $csvfile_template -NoTypeInformation -UseCulture
#------------------- OLD VM Report -------------------#
$csvfile_vm = "C:\VC_reports\$($VCServer + "_" +$date + "_" + "OLD_VM.csv")"
Write-Host -ForegroundColor Yellow "File name - $csvfile_vm"
Get-VMHost | % { Get-VM -Location $_.Name } | where {$_.PowerState -eq "PoweredOff"} |
Select Name, PowerState,
@{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}},
@{N="UsedSpaceGB";E={[math]::Round($_.UsedSpaceGB,1)}},
@{N="ProvisionedSpaceGB";E={[math]::Round($_.ProvisionedSpaceGB,1)}},
@{N="Folder";E={$_.Folder.Name}} |
Export-Csv $csvfile_vm -NoTypeInformation -UseCulture
disconnect-VIserver -Server $VCServer -confirm:$false
}
Similar Posts:
- How to take Live-Backup of VMware(Esxi Server) VM host
- PowerShell and .Net version report on remote computers
- ORACLE Application Express
- Nagios daily and weekly Reporting and log parsing
- Azure VM Inventory report
- Selecting virtual SCSI Controllers for Disks (VMware VM)
- MySQL full DB dump -shell script