Hi
Can somebody please help with a script that I am working on I am trying to gather all VM's and the datastores on which their hard drive reside on along with the canonical name of the datastore
this is what i have at the moment but keep getting errors
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) {
ForEach ($datastore in ($Cluster | get-vmhost | get-datastore | Get-ScsiLun -LunType disk |select -Property CanonicalName)){
"" | Select-Object -Property @{N="VM";E={$VM.Name}},
@{N="Datacenter";E={$Datacenter.name}},
@{N="Cluster";E={$Cluster.Name}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
@{N="CononicalName";E={$datastore.CononicalName}}
@{N="VMDKpath";E={$HardDisk.FileName}}
}
}
}
}
}
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "c:\vmdkPaths.csv"
Error
Get-ScsiLun : 28/08/2013 9:57:30 AM Get-ScsiLun ScsiLun info is available only for Vmfs datstores.
At C:\Users\jsmith484\Documents\PowershellScripts\ICEVMDKReport3.ps1:6 char:68
+ forEach ($datastore in ($Cluster | get-vmhost | get-datastore | Get-ScsiLun - ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ScsiLun], VimException
+ FullyQualifiedErrorId : Client20_StorageServiceImpl_GetScsiLun_InvalidDatastoreType,VMware.VimAutomation.ViCore.Cmdlets.Commands.Hos
t.GetScsiLun
I think its something to do with the way that I am gathering the canonical name using the get-scsilun?