I have this script that pulls my vms with their prospective storage with rdms and hard disks.. I need to modify this to make it automatic job, but with a few additions.
1. add a line to for the job to auto connect to the vc
2. Add # of vcpus and vram to the vms
3. I have this script to give me the results to a location in csv format, but if I can have it email would be better. I saw a post, but I have not tried yet. Doesn't run by asking
Here is the sample script
#This report will report that links the Virtual Machine to its Datastore(s) and the size of the disk allocated. This includes RDMs as well.
$report = foreach($vm in Get-VM){
Get-HardDisk -VM $vm | Select @{N="VM Name";E={$vm.Name}},
@{N="RDM Name";E={($_ | where {"RawPhysical","RawVirtual" -contains $_.DiskType}).FileName}},
@{N="Datastore";E={($_ | where {"RawPhysical","RawVirtual" -notcontains $_.DiskType}).Filename.Split(']')[0].TrimStart('[')}},
@{N="HD Name";E={$_.Name}},
@{N="HD Size GB";E={$_.CapacityKB/1MB}}
}
$report | Export-Csv "C:\evreport.csv" -NoTypeInformation
Try it like this
Connect-VIServer -Server MyVC $report = foreach($vm in Get-VM mmmstd*){ Get-HardDisk -VM $vm | Select @{N="VM Name";E={$vm.Name}}, @{N="RDM Name";E={($_ | where {"RawPhysical","RawVirtual" -contains $_.DiskType}).FileName}}, @{N="Datastore";E={($_ | where {"RawPhysical","RawVirtual" -notcontains $_.DiskType}).Filename.Split(']')[0].TrimStart('[')}}, @{N="HD Name";E={$_.Name}}, @{N="HD Size GB";E={$_.CapacityKB/1MB}}, @{N="vCPU";E={$vm.NumCpu}}, @{N="vRAM (MB)";E={$vm.MemoryMB}} } Send-MailMessage -From "lucd@lucd.info" `
-To "lucd@lucd.info" `
-Subject "VM Report" `
-Body ($report | Out-String) `
-SmtpServer "mail.lucd.info"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try it like this
Connect-VIServer -Server MyVC $report = foreach($vm in Get-VM mmmstd*){ Get-HardDisk -VM $vm | Select @{N="VM Name";E={$vm.Name}}, @{N="RDM Name";E={($_ | where {"RawPhysical","RawVirtual" -contains $_.DiskType}).FileName}}, @{N="Datastore";E={($_ | where {"RawPhysical","RawVirtual" -notcontains $_.DiskType}).Filename.Split(']')[0].TrimStart('[')}}, @{N="HD Name";E={$_.Name}}, @{N="HD Size GB";E={$_.CapacityKB/1MB}}, @{N="vCPU";E={$vm.NumCpu}}, @{N="vRAM (MB)";E={$vm.MemoryMB}} } Send-MailMessage -From "lucd@lucd.info" `
-To "lucd@lucd.info" `
-Subject "VM Report" `
-Body ($report | Out-String) `
-SmtpServer "mail.lucd.info"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
How about scratching the whole send report and just export it to the c drive with a csv extension?
You mean like this
Connect-VIServer -Server MyVC
$report = foreach($vm in Get-VM){
Get-HardDisk -VM $vm | Select @{N="VM Name";E={$vm.Name}},
@{N="RDM Name";E={($_ | where {"RawPhysical","RawVirtual" -contains $_.DiskType}).FileName}},
@{N="Datastore";E={($_ | where {"RawPhysical","RawVirtual" -notcontains $_.DiskType}).Filename.Split(']')[0].TrimStart('[')}},
@{N="HD Name";E={$_.Name}},
@{N="HD Size GB";E={$_.CapacityKB/1MB}},
@{N="vCPU";E={$vm.NumCpu}},
@{N="vRAM (MB)";E={$vm.MemoryMB}}
}
$report | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture
But isn't that the same as what you had in your original script ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yeah just found out that the only requirement that I needed was exporting the results with auto connecting to the vc and adding the the vcpu and vram info. Not sure why I was getting some errors when trying the original script with your modifications. Must be the copy and paste that I missed.. Thank you so much you have been a great help.
I need to really sit down and get really good with this power cli stuff. This stuff is really powerful......