Trying to export VMs and their associated Datastore names to CSV but for the datastore I just extract the "Array name" from the Datastore name. The array name always starts with "P" and has 2 numbers after but the number of characters before, differers.
Please help for the sake of my head (banging on desk)!!
Example:
ServerA NPR_Cluster5_P55_200
ServerB PR_Cluster12_P77_350
I want:
ServerA P55
ServerB. P77
$Report=@()
$clusters = Get-Cluster | where {$_.Name -like "*BAK*"}
foreach ($cluster in $clusters){
$VMs = $cluster | Get-VM | where {$_.Guest -like "*Windows*"}
foreach ($VM in $VMs){
$datastore = $VM | Get-Datastore | Select-Object -ExpandProperty name -First 1
$VMGuest = $VM.ExtensionData.Guest.GuestFullName
$Details ="" | Select VMName,Cluster,Datastore
$Details.VMName =$VM.Name
$Details.Cluster = $VM.VMHost.Parent
$Details.Datastore = $datastore
$Report +=$Details
}
}
$Report | Export-Csv -NoTypeInformation C:\temp\r_VM_to_Array.csv