I have had a report running for any VM not set to the default of automatic, but it doesn't seem to be working and my script to enable the automatic SDRS isn't either. No errors appear though. Here are my scripts:
Enable SDRS:
$si = Get-View ServiceInstance
$srmMgr = Get-View -Id $si.Content.StorageResourceManager
foreach($dsc in Get-DatastoreCluster){
$spec = New-Object VMware.Vim.StorageDrsConfigSpec
foreach($vm in ($dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where{!$_.Enabled})){
$vmSpec = New-Object VMware.Vim.StorageDrsVmConfigSpec
$vmSpec.Info = $vm
$vmSpec.Info.Enabled = $true
$spec.VmConfigSpec += $vmSpec
}
$srmMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)
}
Report SDRS:
#############################
# Variables #
#############################
$date=Get-Date -format "yyyy-MMM-d"
$datetime=Get-Date
$filelocation="/var/www/SDRS/SDRS-$date.htm"
#############################
# Content #
#############################
$report = foreach($dsc in Get-DatastoreCluster){
$defaultVM = $dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.PodConfig.DefaultVmBehavior
foreach($vm in ($dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where{!$_.Enabled})){
Get-View -Id $vm.Vm -Property Name |
Select @{N='DSC';E={$dsc.Name}},
Name,
@{N='Enabled';E={$vm.Enabled}},
@{N='Behavior';E={
if($vm.Behavior){$vm.Behavior}
else{"Default ($($defaultVM))"}
}}
}
}
#############################
# Add Text to the HTML file #
#############################
$report | ConvertTo-Html -title "VMware Hardware Version" -body "<H4>Date and time</H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
Invoke-Item -Path $filelocation
This seems to work for me.
The only issue might be that it does say 'Automated' for the VMs, but it will not say Default.
For that option, you will have to disable/enable SDRS
$si = Get-View ServiceInstance
$srmMgr = Get-View -Id $si.Content.StorageResourceManager
foreach($dsc in Get-DatastoreCluster){
$spec = New-Object VMware.Vim.StorageDrsConfigSpec
foreach($vm in ($dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where{$_.Behavior -eq [VMware.Vim.StorageDrsPodConfigInfoBehavior]::manual})){
$vmSpec = New-Object VMware.Vim.StorageDrsVmConfigSpec
$vmSpec.Operation = [VMware.Vim.ArrayUpdateOperation]::edit
$vmSpec.Info = $vm
$vmSpec.Info.Behavior = [VMware.Vim.StorageDrsPodConfigInfoBehavior]::automated
$spec.VmConfigSpec += $vmSpec
}
$srmMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm not sure what exactly you are trying to do.
All VMs that do not appear in the VM Override window, are reported (since their Enabled property is empty).
When I run you second script, the VMs do appear in the VM Override window.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Afaik that is the Behavior property, not the Enabled property.
It accepts automated or manual.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry not sure how to alter it to change that property
I experimented around, but not getting much luck on this.
To make sure I get what you are trying to do.
In that screenshot earlier, it is the 1st VM that you want to set to Default (Fully Automated)?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Correct!
This seems to work for me.
The only issue might be that it does say 'Automated' for the VMs, but it will not say Default.
For that option, you will have to disable/enable SDRS
$si = Get-View ServiceInstance
$srmMgr = Get-View -Id $si.Content.StorageResourceManager
foreach($dsc in Get-DatastoreCluster){
$spec = New-Object VMware.Vim.StorageDrsConfigSpec
foreach($vm in ($dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where{$_.Behavior -eq [VMware.Vim.StorageDrsPodConfigInfoBehavior]::manual})){
$vmSpec = New-Object VMware.Vim.StorageDrsVmConfigSpec
$vmSpec.Operation = [VMware.Vim.ArrayUpdateOperation]::edit
$vmSpec.Info = $vm
$vmSpec.Info.Behavior = [VMware.Vim.StorageDrsPodConfigInfoBehavior]::automated
$spec.VmConfigSpec += $vmSpec
}
$srmMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference