-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathManage-EsxiUserAccount.ps1
47 lines (37 loc) · 1.58 KB
/
Manage-EsxiUserAccount.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#created by vcloud-lab.com
$vc = 'vCenter.vcloud-lab.com'
$esx = 'esxiserver.vcloud-lab.com'
$vcUser = 'administrator@vsphere.local'
$vcPassword = 'Computer@123'
$newUserName = 'testuser'
$newUserPassword = 'Computer@123'
$permissionRole = 'Admin'
Import-Module VMware.VimAutomation.Core
Connect-VIServer $vc -User $vcUser -Password $vcPassword
$esxcli = Get-EsxCli -VMHost $esx -V2
#List of all esxi accounts Before add
$esxiUserListBeforeAdd = @()
$esxiUserListBeforeAdd = $esxcli.system.permission.list.Invoke()
$esxiUserListBeforeAdd | Format-Table -AutoSize
#Create new user on ESXi
$esxcliArgs = $esxcli.system.account.add.CreateArgs()
$esxcliArgs.id = $newUserName
$esxcliArgs.password = $newUserPassword
$esxcliArgs.passwordconfiguration = $newUserPassword
$esxcliArgs = $esxcli.system.account.add.Invoke($esxcliArgs)
$permissionArg = $esxcli.system.permission.set.CreateArgs()
$permissionArg.id = $newUserName
$permissionArg.role = $permissionRole
$permissionArg = $esxcli.system.permission.set.Invoke($permissionArg)
#List of all esxi account After add
$esxiUserListAfterAdd = @()
$esxiUserListAfterAdd = $esxcli.system.permission.list.Invoke()
$esxiUserListAfterAdd | Format-Table -AutoSize
#Remove the user on ESXi
$esxcliArgs = $esxcli.system.account.remove.CreateArgs()
$esxcliArgs.id = $newUserName
$esxcliArgs = $esxcli.system.account.add.Invoke($esxcliArgs)
#List of all esxi account After delete
$esxiUserListAfterDelete = @()
$esxiUserListAfterDelete = $esxcli.system.permission.list.Invoke()
$esxiUserListAfterDelete | Format-Table -AutoSize