Fixing issues in VAMI and VMware.WorkloadManagement modules
Fixing issues in VAMI and VMware.WorkloadManagement modules
This commit is contained in:
@@ -655,38 +655,48 @@ Function Get-VAMIUser {
|
|||||||
$userAPI = Get-VAMIServiceAPI -NameFilter "accounts"
|
$userAPI = Get-VAMIServiceAPI -NameFilter "accounts"
|
||||||
$UserResults = @()
|
$UserResults = @()
|
||||||
|
|
||||||
if (($Name -ne "") -and ($null -ne $Name)) {
|
# Get a list of users
|
||||||
try {
|
try {
|
||||||
$Users = $UserAPI.get($name)
|
|
||||||
} catch {
|
|
||||||
Write-Error $Error[0].exception.Message
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$Users = $UserAPI.list()
|
$Users = $UserAPI.list()
|
||||||
|
} catch {
|
||||||
|
write-error $_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Apply filtering if Name input is provided
|
||||||
|
if ($Name -ne '' -AND $Name -ne $null) {
|
||||||
|
# For 6.5 API, the username is part of the list returnset; for 6.7/7.x API the value from the list is the username. Because of this we will use an OR filter to account for either case.
|
||||||
|
$Users = $Users | Where-Object {$_.username -eq $name -OR $_.value -eq $name}
|
||||||
|
}
|
||||||
|
|
||||||
if ($Users.status) {
|
if ($Users.status) {
|
||||||
|
# This is for 6.5 API, which has a status property; in newer API response there is an enabled property with values of True/False
|
||||||
foreach ($User in $Users) {
|
foreach ($User in $Users) {
|
||||||
$UserString = [pscustomobject] @{
|
$UserString = [pscustomobject] @{
|
||||||
User = $User.username
|
User = $User.username
|
||||||
Name = $User.fullname
|
Name = $User.fullname
|
||||||
Email = $User.email
|
Email = $User.email
|
||||||
|
Enabled = if ($User.status -eq 'enabled' ) { $true } else { $false }
|
||||||
Status = $User.status
|
Status = $User.status
|
||||||
|
LastPasswordChange = $null
|
||||||
|
PasswordExpiresAt = $null
|
||||||
PasswordStatus = $User.passwordstatus
|
PasswordStatus = $User.passwordstatus
|
||||||
Roles = @($User.role)
|
Roles = @($User.role)
|
||||||
}
|
}
|
||||||
$UserResults += $UserString
|
$UserResults += $UserString
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
# This is for 6.7/7.0+ API response
|
||||||
foreach ($User in $Users) {
|
foreach ($User in $Users) {
|
||||||
$UserInfo = $userAPI.get($user)
|
$UserInfo = $userAPI.get($User.Value)
|
||||||
$UserString = [pscustomobject] @{
|
$UserString = [pscustomobject] @{
|
||||||
User = $User.value
|
User = $User.value
|
||||||
Name = $UserInfo.fullname
|
Name = $UserInfo.fullname
|
||||||
Email = $UserInfo.email
|
Email = $UserInfo.email
|
||||||
Status = $UserInfo.enabled
|
Enabled = $UserInfo.enabled
|
||||||
|
Status = if ($userInfo.enabled ) { 'enabled' } else { 'disabled' }
|
||||||
LastPasswordChange = $UserInfo.last_password_change
|
LastPasswordChange = $UserInfo.last_password_change
|
||||||
PasswordExpiresAt = $UserInfo.password_expires_at
|
PasswordExpiresAt = $UserInfo.password_expires_at
|
||||||
PasswordStatus = if ($UserInfo.has_password) { if ((!!$UserInfo.password_expires_at) -and ([datetime]$UserInfo.password_expires_at -lt (get-date))) {"good"} else {"expired"}} else { "notset"}
|
PasswordStatus = if ($UserInfo.has_password) { if ((!!$UserInfo.password_expires_at) -and ( (Get-Date) -lt [datetime]$UserInfo.password_expires_at)) {'valid'} else {'expired'}} else { 'notset'}
|
||||||
Roles = $UserInfo.roles
|
Roles = $UserInfo.roles
|
||||||
}
|
}
|
||||||
$UserResults += $UserString
|
$UserResults += $UserString
|
||||||
@@ -741,18 +751,19 @@ Function New-VAMIUser {
|
|||||||
|
|
||||||
$userAPI = Get-VAMIServiceAPI -NameFilter "accounts"
|
$userAPI = Get-VAMIServiceAPI -NameFilter "accounts"
|
||||||
if ($userAPI.name -eq 'com.vmware.appliance.techpreview.localaccounts.user') {
|
if ($userAPI.name -eq 'com.vmware.appliance.techpreview.localaccounts.user') {
|
||||||
$CreateSpec = $UserAPI.Help.add.config.CreateExample()
|
$CreateSpec = $UserAPI.Help.add.config.Create()
|
||||||
} else {
|
} else {
|
||||||
$CreateSpec = $UserAPI.Help.create.config.CreateExample()
|
$CreateSpec = $UserAPI.Help.create.config.Create()
|
||||||
}
|
}
|
||||||
|
|
||||||
$CreateSpec.fullname = $FullName
|
|
||||||
$CreateSpec.role = $Role
|
|
||||||
$CreateSpec.email = $Email
|
$CreateSpec.email = $Email
|
||||||
$CreateSpec.password = [VMware.VimAutomation.Cis.Core.Types.V1.Secret]$Password
|
$CreateSpec.password = [VMware.VimAutomation.Cis.Core.Types.V1.Secret]$Password
|
||||||
|
|
||||||
if ($CreateSpec.psobject.properties.name -contains "username") {
|
if ($CreateSpec.psobject.properties.name -contains "username") {
|
||||||
|
# This is for 6.5 API
|
||||||
$CreateSpec.username = $Name
|
$CreateSpec.username = $Name
|
||||||
|
$CreateSpec.fullname = $FullName
|
||||||
|
$CreateSpec.role = $Role
|
||||||
try {
|
try {
|
||||||
Write-Host "Creating new user $Name ..."
|
Write-Host "Creating new user $Name ..."
|
||||||
$UserAPI.add($CreateSpec)
|
$UserAPI.add($CreateSpec)
|
||||||
@@ -760,14 +771,17 @@ Function New-VAMIUser {
|
|||||||
Write-Error $Error[0].exception.Message
|
Write-Error $Error[0].exception.Message
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$CreateSpec.password_expires = $PasswordExpires
|
# This is for 6.7/7.0+ API
|
||||||
|
$CreateSpec.full_name = $FullName
|
||||||
|
$CreateSpec.roles = @($Role)
|
||||||
|
$CreateSpec.password_expires = [string]$PasswordExpires
|
||||||
$CreateSpec.password_expires_at = $PasswordExpiresAt
|
$CreateSpec.password_expires_at = $PasswordExpiresAt
|
||||||
$CreateSpec.max_days_between_password_change = $MaxPasswordAge
|
$CreateSpec.max_days_between_password_change = $MaxPasswordAge
|
||||||
try {
|
try {
|
||||||
Write-Host "Creating new user $Name ..."
|
Write-Host "Creating new user $Name ..."
|
||||||
$UserAPI.create($Name, $CreateSpec)
|
$UserAPI.create($Name, $CreateSpec)
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error $Error[0].exception.Message
|
Write-Error $_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ Function New-WorkloadManagement {
|
|||||||
[Parameter(Mandatory=$True)]$MgmtNetworkGateway,
|
[Parameter(Mandatory=$True)]$MgmtNetworkGateway,
|
||||||
[Parameter(Mandatory=$True)][string[]]$MgmtNetworkDNS,
|
[Parameter(Mandatory=$True)][string[]]$MgmtNetworkDNS,
|
||||||
[Parameter(Mandatory=$True)][string[]]$MgmtNetworkDNSDomain,
|
[Parameter(Mandatory=$True)][string[]]$MgmtNetworkDNSDomain,
|
||||||
[Parameter(Mandatory=$True)]$MgmtNetworkNTP,
|
[Parameter(Mandatory=$True)][string[]]$MgmtNetworkNTP,
|
||||||
[Parameter(Mandatory=$True)]$WorkloadNetworkVDS,
|
[Parameter(Mandatory=$True)]$WorkloadNetworkVDS,
|
||||||
[Parameter(Mandatory=$True)]$WorkloadNetworkEdgeCluster,
|
[Parameter(Mandatory=$True)]$WorkloadNetworkEdgeCluster,
|
||||||
[Parameter(Mandatory=$True)][string[]]$WorkloadNetworkDNS,
|
[Parameter(Mandatory=$True)][string[]]$WorkloadNetworkDNS,
|
||||||
|
|||||||
Reference in New Issue
Block a user