I'm really close on this one I think. The contents of my hostprofile.csv are:
"NAME,STATE,STATUS,% CPU,% MEMORY,LAST TIME EXITED STANDBY,ALARM ACTIONS,AUTODEPLOY.MACHINEIDENTITY,CREATED BY,FUNCTION,NOTIFICATION DL,OWNER/REQUESTER"
"esxdc2s01.DOMAIN.local,Maintenance Mode,Normal,0%,2%,Never,Enabled,,,,,"
"esxdc2s02.DOMAIN.local,Maintenance Mode,Normal,0%,2%,Never,Enabled,,,,,"
"esxdc2s03.DOMAIN.local,Maintenance Mode,Alert,0%,2%,Never,Enabled,,,,,"
And my code is:
$HostList = Import-Csv Hostprofiles.csv
Connect-VIServer -Server VIRTUALCENTER.DOMAIN.local -User "qa\a-dubutcher" -Password MYPASSWORD
# Apply host profile to all the VMs in $HostList
foreach($Host in $HostList) {
Apply-VMHostProfile -Entity $($Host.NAME) -Profile YKFProfile -Confirm:$false
}
And my error message is:
Cannot overwrite variable Host because it is read-only or constant.
At C:\Users\dubutcher\Dropbox\VMware\Scripts\Blackberry_Applyprofile.ps1:6 char
:8
+ foreach <<<< ($Host in $HostList) {
+ CategoryInfo : WriteError: (Host:String) [], SessionStateUnauth
orizedAccessException
+ FullyQualifiedErrorId : VariableNotWritable
Any suggestions?