<?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: Add existing Domain service account to ESXi and map to role and add to exception users list in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-existing-Domain-service-account-to-ESXi-and-map-to-role-and/m-p/2973236#M112315</link>
    <description>&lt;P&gt;Besides the part for the creation/retrieval of the HostAccount, everything should be the same.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Jun 2023 12:54:53 GMT</pubDate>
    <dc:creator>LucD</dc:creator>
    <dc:date>2023-06-15T12:54:53Z</dc:date>
    <item>
      <title>Add existing Domain service account to ESXi and map to role and add to exception users list</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-existing-Domain-service-account-to-ESXi-and-map-to-role-and/m-p/2973233#M112313</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have the below script which was kindly put together by LucD.&lt;/P&gt;&lt;P&gt;The current script creates a local account, creates the role, maps the account to the role and adds user to the lockdown exceptions.&lt;/P&gt;&lt;P&gt;The change I wish to make is instead of creating a local account, I want the script to get the domain account RAC\svc_test_01 and carry out the rest accordingly.&lt;/P&gt;&lt;P&gt;Please help, any help will be much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$newUsers = "svc_test_lt01","svc_test_lt02"&lt;BR /&gt;$newPassword = "VMware1!"&lt;BR /&gt;$roleName = "test_Role"&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" |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;$srv = Connect-VIServer -Server $_.Hostname -User 'root' -Password 'Password01'&lt;BR /&gt;$priv = Get-VIPrivilege | Where-Object { $_.Id -in $privileges }&lt;/P&gt;&lt;P&gt;# If Role exists assign new privileges, else create Role&lt;BR /&gt;$role = Get-VIRole -Name $roleName -ErrorAction SilentlyContinue&lt;BR /&gt;if ($role) {&lt;BR /&gt;$role = Set-VIRole -Role $role -AddPrivilege $priv -Confirm:$false&lt;BR /&gt;} else {&lt;BR /&gt;$role = New-VIRole -Name $roleName -Privilege $priv -Server $srv -Confirm:$false&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;$accounts = @()&lt;BR /&gt;$newUSers | ForEach-Object -Process {&lt;BR /&gt;# If Account exists set new password, else create Account&lt;BR /&gt;$account = Get-VMHostAccount -Id $_ -ErrorAction SilentlyContinue&lt;BR /&gt;if ($account) {&lt;BR /&gt;$account = Set-VMHostAccount -UserAccount $account -Password $newPassword&lt;BR /&gt;} else {&lt;BR /&gt;$account = New-VMHostAccount -Id $_ -Password $newPassword -GrantShellAccess:$true `&lt;BR /&gt;-Description 'test User Access' -UserAccount -Server $srv&lt;BR /&gt;}&lt;BR /&gt;$accounts += $account&lt;/P&gt;&lt;P&gt;# If Permission exists set new Role, else create Permission&lt;BR /&gt;$folder = Get-Folder -Name "root" -Server $srv&lt;BR /&gt;$perm = Get-VIPermission -Entity $folder -Principal $_ -ErrorAction SilentlyContinue&lt;BR /&gt;if (!$perm) {&lt;BR /&gt;$perm = New-VIPermission -Entity $folder -Principal $_ -Role $role -Server $srv -Propagate $true -Confirm:$false&lt;BR /&gt;} else {&lt;BR /&gt;$perm = Set-VIPermission -Permission $perm -Role $role -Propagate $true&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;# Add users to lockdown exceptions&lt;BR /&gt;$esx = Get-VMHost&lt;BR /&gt;$accessMgr = Get-View $esx.ExtensionData.ConfigManager.HostAccessManager&lt;/P&gt;&lt;P&gt;$oldLockDownMode = $accessMgr.LockdownMode&lt;BR /&gt;if ($oldLockDownMode -ne [VMware.Vim.HostLockdownMode]::lockdownDisabled) {&lt;BR /&gt;$accessMgr.ChangeLockdownMode([VMware.Vim.HostLockdownMode]::lockdownDisabled)&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;$accessMgr.UpdateLockdownExceptions($accounts)&lt;/P&gt;&lt;P&gt;if ($oldLockDownMode -ne [VMware.Vim.HostLockdownMode]::lockdownDisabled) {&lt;BR /&gt;$accessMgr.ChangeLockdownMode($oldLockDownMode)&lt;BR /&gt;}&lt;/P&gt;&lt;P&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>Thu, 15 Jun 2023 12:36:22 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-existing-Domain-service-account-to-ESXi-and-map-to-role-and/m-p/2973233#M112313</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-06-15T12:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Add existing Domain service account to ESXi and map to role and add to exception users list</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-existing-Domain-service-account-to-ESXi-and-map-to-role-and/m-p/2973236#M112315</link>
      <description>&lt;P&gt;Besides the part for the creation/retrieval of the HostAccount, everything should be the same.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 12:54:53 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-existing-Domain-service-account-to-ESXi-and-map-to-role-and/m-p/2973236#M112315</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-06-15T12:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Add existing Domain service account to ESXi and map to role and add to exception users list</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-existing-Domain-service-account-to-ESXi-and-map-to-role-and/m-p/2973239#M112316</link>
      <description>&lt;P&gt;Thanks LucD,&lt;/P&gt;&lt;P&gt;Can you let me know which lines to edit/change, so I can test the script please. Unfortunately, I'm not a scripter and trying my best to learn. &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;Thanks&lt;/P&gt;&lt;P&gt;Mo&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 13:01:24 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-existing-Domain-service-account-to-ESXi-and-map-to-role-and/m-p/2973239#M112316</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-06-15T13:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Add existing Domain service account to ESXi and map to role and add to exception users list</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-existing-Domain-service-account-to-ESXi-and-map-to-role-and/m-p/2973241#M112317</link>
      <description>&lt;P&gt;You could start with something like this&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$newUsers = "RAC\svc_test_01", "RAC\svc_test_02"
$newPassword = "VMware1!"
$roleName = "test_Role"
$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 'Password01'
        $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
        }

        $newUSers | ForEach-Object -Process {
            # 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($newUSers)

        if ($oldLockDownMode -ne [VMware.Vim.HostLockdownMode]::lockdownDisabled) {
            $accessMgr.ChangeLockdownMode($oldLockDownMode)
        }

        Disconnect-VIServer -Server $srv -Confirm:$false
    }
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 15 Jun 2023 13:11:50 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-existing-Domain-service-account-to-ESXi-and-map-to-role-and/m-p/2973241#M112317</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-06-15T13:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: Add existing Domain service account to ESXi and map to role and add to exception users list</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-existing-Domain-service-account-to-ESXi-and-map-to-role-and/m-p/2974354#M112383</link>
      <description>&lt;P&gt;Hi LucD,&lt;/P&gt;&lt;P&gt;Worked like a dreammmmmmmmmmmmmmmmmm...!&lt;/P&gt;&lt;P&gt;Again thank you and god bless you &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, 23 Jun 2023 10:46:14 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Add-existing-Domain-service-account-to-ESXi-and-map-to-role-and/m-p/2974354#M112383</guid>
      <dc:creator>mbabu1</dc:creator>
      <dc:date>2023-06-23T10:46:14Z</dc:date>
    </item>
  </channel>
</rss>

