Hello, I have a script where I already raise a post sometimes ago.
Basically I set this script to run in two different vcenter every day but in different time,
$VMS = get-vm
$report = @()
foreach ($vm in $VMS) {
$row = "" | select "VM","DNS Name",PowerState,CPU,Memory,DiskProvisioned,DiskUsed,Cluster,Version
$row."VM" = $vm.Name
$row."DNS Name" = $vm.Guest.get_HostName()
$row.PowerState = $vm.PowerState
$row.CPU = $vm.NumCPU
$row.Memory = $vm.MemoryGb
$row.DiskProvisioned = $vm.ProvisionedSpaceGB
$row.DiskUsed = [Math]::Round($vm.UsedSpaceGB,2)
$row.Cluster = ($vm | get-cluster).Name
$row.Version = $vm.Version
$report += $row
}
I have a request now to modify (if possible):
A unique script for both vcenter who generate only one file csv or a way to combine both file in a unique file and send via SCP to another server.
Also, date format should be like this: 'dd-mm-yyyy_hh-mm-ss'
I'm testing if will work with this format (customer request) :
$report | export-csv -Path "C:\Users\gemela\Desktop\reportVM__$(Get-Date -Format 'yyyy_MM_dd_hh_mm').csv" -NoTypeInformation -UseCulture
Thanks 🙂
Try like this.
The script assumes you are connected to both vCenters.
Get-VM -Server $vc |
Select @{N='vCenter';E={$vc.Name}},Name,
@{N='DNS Name';E={$_.Guest.get_HostName()}},
PowerState,NumCPU,MemoryGb,
@{N='ProvisionedSpaceGB';E={[Math]::Round($_.ProvisionedSpaceGB,2)}},
@{N='DiskUsed';E={[Math]::Round($_.UsedSpaceGB,2)}},
@{N='Cluster';E={Get-Cluster -VM $_ | Select -ExpandProperty Name}},
Version
}
$report |
Export-Csv -Path "C:\Users\gemela\Desktop\reportVM__$(Get-Date -Format 'yyyy-MM-dd_HH-mm').csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can you reach the two vCenters from the station where you run the script?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, I use to run from a jump server both script.
Try like this.
The script assumes you are connected to both vCenters.
Get-VM -Server $vc |
Select @{N='vCenter';E={$vc.Name}},Name,
@{N='DNS Name';E={$_.Guest.get_HostName()}},
PowerState,NumCPU,MemoryGb,
@{N='ProvisionedSpaceGB';E={[Math]::Round($_.ProvisionedSpaceGB,2)}},
@{N='DiskUsed';E={[Math]::Round($_.UsedSpaceGB,2)}},
@{N='Cluster';E={Get-Cluster -VM $_ | Select -ExpandProperty Name}},
Version
}
$report |
Export-Csv -Path "C:\Users\gemela\Desktop\reportVM__$(Get-Date -Format 'yyyy-MM-dd_HH-mm').csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great, it works 🙂 Thanks a lot LucD
I would like to send every day the new file to another machine,
Is possible to put just the latest file every day?
Start-Process 'C:\Program Files (x86)\PuTTY\pscp.exe' -ArgumentList ("-scp -pw ******* C:\Smartlist\file smartlist@10.10.10.10 :/opt/invoicing/smartlist")
You can pick the most recent file like this
Sort-Object -Property LastWriteTime -Descending |
select -First 1 -ExpandProperty FullName
$sProc = @{
FilePath = 'C:\Program Files (x86)\PuTTY\pscp.exe'
ArgumentList = "-scp -pw ******* $file smartlist@10.10.10.10 :/opt/invoicing/smartlist"
}
Start-Process @sProc
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot LucD