<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: All multiple privileges fao LucD in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967386#M111884</link>
    <description>&lt;P&gt;Like this&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$vcenter = 'VCSA01'
$Cluster= 'Clus01'
$Username = 'admin@local'
$password = 'Password01'

$AdminCredential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, (ConvertTo-SecureString -String $password -AsPlainText -Force)

Connect-VIServer -Server $vcenter -Credential $AdminCredential | Out-Null

Get-Cluster -Name $Cluster | Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
    $accessMgr = Get-View -Id $esx.ExtensionData.ConfigManager.hostAccessManager
    if ($accessMgr.LockdownMode -in [VMware.Vim.HostLockdownMode]::lockdownNormal,[VMware.Vim.HostLockdownMode]::lockdownStrict) {
        $accessMgr.ChangeLockdownMode([VMware.Vim.HostLockdownMode]::lockdownDisabled)
    }
}

Disconnect-VIServer -Server $vcenter -Force -confirm:$false
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 08 May 2023 19:12:10 GMT</pubDate>
    <dc:creator>LucD</dc:creator>
    <dc:date>2023-05-08T19:12:10Z</dc:date>
    <item>
      <title>Add multiple privileges fao LucD - Help</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2966840#M111814</link>
      <description>&lt;P&gt;Hi LucD,&lt;/P&gt;&lt;P&gt;I hope your well, I have found the following script and wish to replace the 'datastore.browse' privilege with the following:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Root&amp;gt;Authorisation&amp;gt;ModifyPermissions&lt;/P&gt;&lt;P&gt;Root&amp;gt;Host&amp;gt;Config&amp;gt; SystemManagement&lt;/P&gt;&lt;P&gt;Root&amp;gt;Host&amp;gt;Local&amp;gt; ManageUserGroups&lt;/P&gt;&lt;P&gt;Root&amp;gt;System&amp;gt;All&lt;/P&gt;&lt;P&gt;Do I add a line for each of the above or is there an easier way. Please advise and feel free to edit your script &lt;img class="lia-deferred-image lia-image-emoji" src="https://communities.vmware.com/html/@3CBC42A1E7848F607FD419D398107BF9/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;&lt;P&gt;$newUser = "newuser1"&lt;BR /&gt;$newPassword = "Password123"&lt;BR /&gt;$roleName = "test_role"&lt;/P&gt;&lt;P&gt;Import-Csv "C:\Temp\Mo\hosts.csv" | %{&lt;BR /&gt;$srv = Connect-VIServer -Server $_.Hostname -User 'root' -Password 'rootpassword'&lt;BR /&gt;$priv = Get-VIPrivilege -Server $srv | where {$_.Id -eq "Datastore.Browse"}&lt;BR /&gt;$role = Get-VIRole -Name $roleName -ErrorAction SilentlyContinue&lt;BR /&gt;if(!$role){&lt;BR /&gt;$role = New-VIRole -Name $roleName -Privilege $priv -Server $srv -Confirm:$false&lt;BR /&gt;}&lt;BR /&gt;$account = Get-VMHostAccount -Id $newUser -ErrorAction SilentlyContinue&lt;BR /&gt;if($account){&lt;BR /&gt;Set-VMHostAccount -UserAccount $account -Password $newPassword }&lt;BR /&gt;else{&lt;BR /&gt;New-VMHostAccount -Id $newUser -Password $newPassword -GrantShellAccess:$true `&lt;BR /&gt;-AssignGroups 'root' -Description 'Test user creation' -UserAccount -Server $srv&lt;BR /&gt;}&lt;BR /&gt;$folder = Get-Folder -Name "ha-folder-root" -Server $srv&lt;BR /&gt;$perm = Get-VIPermission -Entity $folder -Principal $newUser -ErrorAction SilentlyContinue&lt;BR /&gt;if(!$perm){&lt;BR /&gt;New-VIPermission -Entity $folder -Principal $newUser -Role $role -Server $srv -Propagate $true -Confirm:$false&lt;BR /&gt;}&lt;BR /&gt;else{&lt;BR /&gt;Set-VIPermission -Permission $perm -Role $role -Propagate&lt;BR /&gt;}&lt;BR /&gt;Disconnect-VIServer -Server $srv -Confirm:$false&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 09:23:21 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2966840#M111814</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-05-05T09:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2966844#M111815</link>
      <description>&lt;P&gt;In addition to the above the 'newuser1' needs to be added to the &lt;STRONG&gt;Exception users&lt;/STRONG&gt;&amp;nbsp;under lockdown mode.Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 17:00:39 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2966844#M111815</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-05-04T17:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2966968#M111821</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$newUser = "newuser1"
$newPassword = "Password123"
$roleName = "test_role"
$privileges = 'Authorization.ModifyPermissions', 'Host.Config.SystemManagement', 'Host.Local.ManageUserGroups'

Import-Csv "C:\Temp\Mo\hosts.csv" | ForEach-Object {
  $srv = Connect-VIServer -Server $_.Hostname -User 'root' -Password 'rootpassword'
  $priv = Get-VIPrivilege | Where-Object { $_.Id -in $privileges}
  $role = Get-VIRole -Name $roleName -ErrorAction SilentlyContinue
  if (!$role) {
    $role = New-VIRole -Name $roleName -Privilege $priv -Server $srv -Confirm:$false
  }
  $account = Get-VMHostAccount -Id $newUser -ErrorAction SilentlyContinue
  if ($account) {
    Set-VMHostAccount -UserAccorount $account -Password $newPassword
  } else {
    New-VMHostAccount -Id $newUser -Password $newPassword -GrantShellAccess:$true `
      -AssignGroups 'root' -Description 'Test user creation' -UserAccount -Server $srv
  }
  $folder = Get-Folder -Name "ha-folder-root" -Server $srv
  $perm = Get-VIPermission -Entity $folder -Principal $newUser -ErrorAction SilentlyContinue
  if (!$perm) {
    New-VIPermission -Entity $folder -Principal $newUser -Role $role -Server $srv -Propagate $true -Confirm:$false
  } else {
    Set-VIPermission -Permission $perm -Role $role -Propagate
  }

  # Add user to lockdown exceptions
  $esx = Get-VMHost
  $accessMgr = Get-View $esx.ExtensionData.ConfigManager.HostAccessManager
  $accessMgr.UpdateLockdownExceptions($account)

  Disconnect-VIServer -Server $srv -Confirm:$false
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 05 May 2023 11:13:52 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2966968#M111821</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-05-05T11:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2966972#M111823</link>
      <description>&lt;P&gt;Hi LucD,&lt;/P&gt;&lt;P&gt;Thank you for the above, I am getting the attached error. Please advise where i'm going wrong. I am testing this on one host atm.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Mo&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 11:32:47 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2966972#M111823</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-05-05T11:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2966973#M111824</link>
      <description>&lt;P&gt;That 1st error seems to indicate you have multiple open connections.&lt;BR /&gt;Check what is $global:defaultVIServers.&lt;BR /&gt;&lt;BR /&gt;Then there are a number of other errors.&lt;BR /&gt;- your current ESXi version does not support LocalGroups anymore&lt;BR /&gt;- again some errors indicating you have a VCSA connection open&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 11:38:43 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2966973#M111824</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-05-05T11:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967017#M111834</link>
      <description>&lt;P&gt;Thanks LucD,&lt;/P&gt;&lt;P&gt;I have force disconnected the vcsa connections and re-run the script.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Version of vCenter is 6.7 18485185&lt;/P&gt;&lt;P&gt;Host is&amp;nbsp; VMware ESXi, 6.7.0, 16316930.&lt;/P&gt;&lt;P&gt;I now get the attached error.&lt;/P&gt;&lt;P&gt;Please advise Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 14:55:10 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967017#M111834</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-05-05T14:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967026#M111835</link>
      <description>&lt;P&gt;I think the error is very clear, the LocalGroup option is not supported anymore.&lt;BR /&gt;That script will not work in your environment.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 15:33:35 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967026#M111835</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-05-05T15:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967028#M111836</link>
      <description>&lt;P&gt;Thanks LucD,&lt;/P&gt;&lt;P&gt;Is there a script in your arsenal that will work in my environment? Please share and I can test.&lt;/P&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many Thanks&lt;/P&gt;&lt;P&gt;Mo&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 15:41:53 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967028#M111836</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-05-05T15:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967052#M111839</link>
      <description>&lt;P&gt;Hi LucD,&lt;/P&gt;&lt;P&gt;I have managed to edit the script as follows and got it working, but the following is not working:&lt;/P&gt;&lt;P&gt;1. Adding to exception user list is not working&lt;/P&gt;&lt;P&gt;2. Disable the lockdown mode, add the user and enable it again. (disable and enable commands missing)&lt;/P&gt;&lt;P&gt;$newUser = "testuser"&lt;BR /&gt;$newPassword = "Password123"&lt;BR /&gt;$roleName = "testing"&lt;BR /&gt;$privileges = 'Authorization.ModifyPermissions', 'Host.Config.SystemManagement', 'Host.Local.ManageUserGroups'&lt;/P&gt;&lt;P&gt;Import-Csv "C:\Temp\Mo\hosts.csv" | ForEach-Object {&lt;BR /&gt;$srv = Connect-VIServer -Server $_.Hostname -User 'root' -Password 'Password1234'&lt;BR /&gt;$priv = Get-VIPrivilege | Where-Object { $_.Id -in $privileges}&lt;BR /&gt;$role = Get-VIRole -Name $roleName -ErrorAction SilentlyContinue&lt;BR /&gt;if (!$role) {&lt;BR /&gt;$role = New-VIRole -Name $roleName -Privilege $priv -Server $srv -Confirm:$false&lt;BR /&gt;}&lt;BR /&gt;$account = Get-VMHostAccount -Id $newUser -ErrorAction SilentlyContinue&lt;BR /&gt;if ($account) {&lt;BR /&gt;Set-VMHostAccount -UserAccount $account -Password $newPassword&lt;BR /&gt;} else {&lt;BR /&gt;New-VMHostAccount -Id $newUser -Password $newPassword -GrantShellAccess:$true `&lt;BR /&gt;-AssignGroups 'root' -Description 'Test user creation' -UserAccount -Server $srv&lt;BR /&gt;}&lt;BR /&gt;$folder = Get-Folder -Name "root" -Server $srv&lt;BR /&gt;$perm = Get-VIPermission -Entity $folder -Principal $newUser -ErrorAction SilentlyContinue&lt;BR /&gt;if (!$perm) {&lt;BR /&gt;New-VIPermission -Entity $folder -Principal $newUser -Role $role -Server $srv -Propagate $true -Confirm:$false&lt;BR /&gt;} else {&lt;BR /&gt;Set-VIPermission -Permission $perm -Role $role -Propagate&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;# Add user to lockdown exceptions&lt;BR /&gt;$esx = Get-VMHost&lt;BR /&gt;$accessMgr = Get-View $esx.ExtensionData.ConfigManager.HostAccessManager&lt;BR /&gt;$accessMgr.UpdateLockdownExceptions($account)&lt;/P&gt;&lt;P&gt;Disconnect-VIServer -Server $srv -Confirm:$false&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Please can you do your magic &lt;img class="lia-deferred-image lia-image-emoji" src="https://communities.vmware.com/html/@3CBC42A1E7848F607FD419D398107BF9/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 19:59:33 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967052#M111839</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-05-05T19:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967061#M111842</link>
      <description>&lt;P&gt;Have look at&amp;nbsp;&lt;A href="https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Having-issues-with-adding-a-user-to-the-exceptions-lists/m-p/2807500/highlight/true#M97981" target="_blank"&gt;Re: Having issues with adding a user to the except... - VMware Technology Network VMTN&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 20:57:56 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967061#M111842</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-05-05T20:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967169#M111849</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$newUser = "testuser"
$newPassword = "VMware1!"
$roleName = "testing"
$privileges = 'Authorization.ModifyPermissions', 'Host.Config.SystemManagement', 'Host.Local.ManageUserGroups'

Import-Csv "C:\Temp\Mo\hosts.csv" |
ForEach-Object -Process {
  $srv = Connect-VIServer -Server $_.Hostname -User 'root' -Password 'Welcome2022!'
  $priv = Get-VIPrivilege | Where-Object { $_.Id -in $privileges }

  # If Role exists assign new privileges, else create Role
  $role = Get-VIRole -Name $roleName -ErrorAction SilentlyContinue
  if($role){
    $role = Set-VIRole -Role $role -AddPrivilege $priv -Confirm:$false
  }
  else{
    $role = New-VIRole -Name $roleName -Privilege $priv -Server $srv -Confirm:$false
  }

  # If Account exists set new password, else create Account
  $account = Get-VMHostAccount -Id $newUser -ErrorAction SilentlyContinue
  if ($account) {
    $account = Set-VMHostAccount -UserAccount $account -Password $newPassword
  } else {
    $account = New-VMHostAccount -Id $newUser -Password $newPassword -GrantShellAccess:$true `
      -Description 'Test user creation' -UserAccount -Server $srv
  }

  # If Permission exists set new Role, else create Permission
  $folder = Get-Folder -Name "root" -Server $srv
  $perm = Get-VIPermission -Entity $folder -Principal $newUser -ErrorAction SilentlyContinue
  if (!$perm) {
    $perm = New-VIPermission -Entity $folder -Principal $newUser -Role $role -Server $srv -Propagate $true -Confirm:$false
  } else {
    $perm = Set-VIPermission -Permission $perm -Role $role -Propagate $true
  }

  # Add user to lockdown exceptions
  $esx = Get-VMHost
  $accessMgr = Get-View $esx.ExtensionData.ConfigManager.HostAccessManager

  $oldLockDownMode = $accessMgr.LockdownMode
  if ($oldLockDownMode -ne [VMware.Vim.HostLockdownMode]::lockdownDisabled){
    $accessMgr.ChangeLockdownMode([VMware.Vim.HostLockdownMode]::lockdownDisabled)
  }

  $accessMgr.UpdateLockdownExceptions($account)

  if ($oldLockDownMode -ne [VMware.Vim.HostLockdownMode]::lockdownDisabled) {
    $accessMgr.ChangeLockdownMode($oldLockDownMode)
  }

  Disconnect-VIServer -Server $srv -Confirm:$false
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 13:41:46 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967169#M111849</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-05-08T13:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967272#M111862</link>
      <description>&lt;P&gt;Hi LucD,&lt;/P&gt;&lt;P&gt;Thank you for the above, the script creates the role with the correct permissions but fails to create the user and add the user to the exception users list in lockdown mode.&lt;/P&gt;&lt;P&gt;See attached errors for your reference.&lt;/P&gt;&lt;P&gt;Please advise and let me know if I am doing something wrong.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 13:33:56 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967272#M111862</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-05-08T13:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967275#M111863</link>
      <description>&lt;P&gt;The account creation still tries to assign a group, that is not supported anymore.&lt;BR /&gt;That is what the error is saying, I don't see anything related to an exception list&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 13:43:29 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967275#M111863</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-05-08T13:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967291#M111864</link>
      <description>&lt;P&gt;Hi LucD,&lt;/P&gt;&lt;P&gt;Its strange we don't see an error for not adding to the exceptions list. When we try the attached script, it creates the user and adds it to the exception list, but doesn't create the role. Can we use the commands for adding to the exceptions list from the attached and add it to the above script you have created. Then we can test if it works.&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 14:29:01 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967291#M111864</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-05-08T14:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967330#M111867</link>
      <description>&lt;P&gt;You can do whatever you want, even ask Wouter.&lt;BR /&gt;&lt;BR /&gt;For me the snippet creates the Role, not sure why it wouldn't work for you.&lt;BR /&gt;At least there should be an error message if something goes wrong.&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 15:31:01 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967330#M111867</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-05-08T15:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967347#M111871</link>
      <description>&lt;P&gt;Hi LucD,&lt;/P&gt;&lt;P&gt;Apologies, I was making a silly mistake when editing the script. As always all works like a dream...you Da Genius.&lt;/P&gt;&lt;P&gt;If&amp;nbsp; I want to add two users at the same time (testuser1 and testuser2) can I do this on the same script or do i need to run the script twice changing the newuser field. And will have to add the below somewhere in the above script aswell I assume.&lt;/P&gt;&lt;P&gt;$HostAccess = Get-View -Id $vmhost.ExtensionData.ConfigManager.HostAccessManager&lt;BR /&gt;$currentUsers = $HostAcces.QueryLockdownExceptions()&lt;BR /&gt;$newUsers = $currentUsers + $username&lt;BR /&gt;$HostAccess.UpdateLockdownExceptions($newUsers)&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 16:56:10 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967347#M111871</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-05-08T16:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967356#M111872</link>
      <description>&lt;P&gt;You could do something like this&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$newUsers = "testuser1", "testuser2"
$newPassword = "VMware1!"
$roleName = "testing"
$privileges = 'Authorization.ModifyPermissions', 'Host.Config.SystemManagement', 'Host.Local.ManageUserGroups'

Import-Csv "C:\Temp\Mo\hosts.csv" |
    ForEach-Object -Process {
        $srv = Connect-VIServer -Server $_.Hostname -User 'root' -Password 'Welcome2022!'
        $priv = Get-VIPrivilege | Where-Object { $_.Id -in $privileges }

        # If Role exists assign new privileges, else create Role
        $role = Get-VIRole -Name $roleName -ErrorAction SilentlyContinue
        if ($role) {
            $role = Set-VIRole -Role $role -AddPrivilege $priv -Confirm:$false
        } else {
            $role = New-VIRole -Name $roleName -Privilege $priv -Server $srv -Confirm:$false
        }

        $accounts = @()
        $newUSers | ForEach-Object -Process {
            # If Account exists set new password, else create Account
            $account = Get-VMHostAccount -Id $_ -ErrorAction SilentlyContinue
            if ($account) {
                $account = Set-VMHostAccount -UserAccount $account -Password $newPassword
            } else {
                $account = New-VMHostAccount -Id $_ -Password $newPassword -GrantShellAccess:$true `
                    -Description 'Test user creation' -UserAccount -Server $srv
            }
            $accounts += $account

            # If Permission exists set new Role, else create Permission
            $folder = Get-Folder -Name "root" -Server $srv
            $perm = Get-VIPermission -Entity $folder -Principal $_ -ErrorAction SilentlyContinue
            if (!$perm) {
                $perm = New-VIPermission -Entity $folder -Principal $_ -Role $role -Server $srv -Propagate $true -Confirm:$false
            } else {
                $perm = Set-VIPermission -Permission $perm -Role $role -Propagate $true
            }
        }

        # Add users to lockdown exceptions
        $esx = Get-VMHost
        $accessMgr = Get-View $esx.ExtensionData.ConfigManager.HostAccessManager

        $oldLockDownMode = $accessMgr.LockdownMode
        if ($oldLockDownMode -ne [VMware.Vim.HostLockdownMode]::lockdownDisabled) {
            $accessMgr.ChangeLockdownMode([VMware.Vim.HostLockdownMode]::lockdownDisabled)
        }

        $accessMgr.UpdateLockdownExceptions($accounts)

        if ($oldLockDownMode -ne [VMware.Vim.HostLockdownMode]::lockdownDisabled) {
            $accessMgr.ChangeLockdownMode($oldLockDownMode)
        }

        Disconnect-VIServer -Server $srv -Confirm:$false
    }&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 08 May 2023 17:15:28 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967356#M111872</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-05-08T17:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967371#M111874</link>
      <description>&lt;P&gt;Hi LucD,&lt;/P&gt;&lt;P&gt;Perfect, the above works perfectly. I have found the cluster has all the hosts in lockdown mode (Normal) and I need to manually disable the lockdown mode for the script to access the host and run accordingly.&lt;/P&gt;&lt;P&gt;Is there anyway of adding in the script to disable lockdown mode, run the script and enable lockdown mode at the end. I assume you will need to access the vCenter. Happy to add in the vCenter name.&lt;/P&gt;&lt;P&gt;Please advise.&lt;/P&gt;&lt;P&gt;Many Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 18:07:46 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967371#M111874</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-05-08T18:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967372#M111875</link>
      <description>&lt;P&gt;Not while you are connected to the ESXi node itself.&lt;BR /&gt;When you have all these ESXi nodes connected to a vCenter, you could probably automate it from there.&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 18:10:58 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967372#M111875</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-05-08T18:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: All multiple privileges fao LucD</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967375#M111877</link>
      <description>&lt;P&gt;Thanks LucD,&lt;/P&gt;&lt;P&gt;Is the a sperate small script available I can run to disable/enable the lockdown mode in the environment using the vcenter.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;Mo&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 18:17:53 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-multiple-privileges-fao-LucD-Help/m-p/2967375#M111877</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-05-08T18:17:53Z</dc:date>
    </item>
  </channel>
</rss>

