Author: Rahul Jumde

Template and Powered OFF VM’s Report from vCenter server

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

}
PowerShell and .Net version report on remote computers

PowerShell and .Net version report on remote computers

Hi Friends,

Here is powershell script to pull out report of PowerShell and .Net version on remote computer.

$computers = Get-Content -Path “C:\serverlist.txt”

ForEach($computer in $computers){
If(!(Test-Connection -ComputerName $computer -Count 1 -Quiet)) {
Write-Host -ForegroundColor Red “$computer is offline. Proceeding with next computer”
continue
} else {
Invoke-Command -ComputerName $computer -ScriptBlock {
$Lookup = @{
378389 = [version]’4.5′
378675 = [version]’4.5.1′
378758 = [version]’4.5.1′
379893 = [version]’4.5.2′
393295 = [version]’4.6′
393297 = [version]’4.6′
394254 = [version]’4.6.1′
394271 = [version]’4.6.1′
394802 = [version]’4.6.2′
394806 = [version]’4.6.2′
460798 = [version]’4.7′
460805 = [version]’4.7′
461308 = [version]’4.7.1′
461310 = [version]’4.7.1′
461808 = [version]’4.7.2′
461814 = [version]’4.7.2′
528040 = [version]’4.8′
528049 = [version]’4.8′
}

$computerOS = Get-WmiObject -Class Win32_OperatingSystem | Select-Object CSName,Caption
$OS = $computerOS.Caption
$ComputerN = $computerOS.CSName
$info = Get-ChildItem ‘HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP’ -Recurse -ErrorAction SilentlyContinue |
Get-ItemProperty -name Version, Release -EA 0 |
Where-Object { $_.PSChildName -eq “Full”} | Select-Object PSComputerName, Version, Release
$netversion = $info.Version
$netrelease = $info.Release
$com = $info.PSComputerName
$PSver = $PSVersionTable.PSVersion.ToString()

New-Object -TypeName PSObject -Property @{
“ComputerName” = $ComputerN
“OperatingSystem” = $OS
“DotNetFramework” = $netversion
“DotNetRelease” = $netrelease
“PowerShellVersion” = $PSver
} | Select-Object ComputerName, OperatingSystem, DotNetFramework, DotNetRelease, PowerShellVersion | FT
}
}
}