Merge pull request #382 from dunsdon/patch-4

Update VAMI.psm1
This commit is contained in:
dmilov
2020-09-23 10:07:29 +03:00
committed by GitHub

View File

@@ -1,4 +1,4 @@
Function Get-VAMISummary { Function Get-VAMISummary {
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
@@ -17,7 +17,7 @@
Get-VAMISummary Get-VAMISummary
#> #>
$systemVersionAPI = Get-CisService -Name 'com.vmware.appliance.system.version' $systemVersionAPI = Get-CisService -Name 'com.vmware.appliance.system.version'
$results = $systemVersionAPI.get() | select product, type, version, build, install_time $results = $systemVersionAPI.get() | select product, type, version, build, install_time, releasedate
$systemUptimeAPI = Get-CisService -Name 'com.vmware.appliance.system.uptime' $systemUptimeAPI = Get-CisService -Name 'com.vmware.appliance.system.uptime'
$ts = [timespan]::fromseconds($systemUptimeAPI.get().toString()) $ts = [timespan]::fromseconds($systemUptimeAPI.get().toString())
@@ -29,6 +29,7 @@
Version = $results.version; Version = $results.version;
Build = $results.build; Build = $results.build;
InstallTime = $results.install_time; InstallTime = $results.install_time;
ReleaseDate = $results.releasedate;
Uptime = $uptime Uptime = $uptime
} }
$summaryResult $summaryResult
@@ -109,6 +110,7 @@ Function Get-VAMIAccess {
Console = $consoleAccess; Console = $consoleAccess;
DCUI = $dcuiAccess; DCUI = $dcuiAccess;
BashShell = $shellAccess.enabled; BashShell = $shellAccess.enabled;
BashTimeout = $shellAccess.timeout;
SSH = $sshAccess SSH = $sshAccess
} }
$accessResult $accessResult
@@ -122,7 +124,10 @@ Function Get-VAMITime {
Organization: VMware Organization: VMware
Blog: www.virtuallyghetto.com Blog: www.virtuallyghetto.com
Twitter: @lamw Twitter: @lamw
=========================================================================== Modifed by: Michael Dunsdon
Twitter: @MJDunsdon
Date: September 16, 2020
===========================================================================
.SYNOPSIS .SYNOPSIS
This function retrieves the time and NTP info from VAMI interface (5480) This function retrieves the time and NTP info from VAMI interface (5480)
for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA.
@@ -131,12 +136,16 @@ Function Get-VAMITime {
.EXAMPLE .EXAMPLE
Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VAMITime Get-VAMITime
.NOTES
Modified script to account for Newer VCSA. Script supports 6.5 and 6.7 VCSAs
#> #>
$systemTimeAPI = Get-CisService -Name 'com.vmware.appliance.system.time' $systemTimeAPI = ( Get-VAMIServiceAPI -NameFilter "system.time")
$timeResults = $systemTimeAPI.get() $timeResults = $systemTimeAPI.get()
$timeSync = (Get-CisService -Name 'com.vmware.appliance.techpreview.timesync').get() $timeSyncMode = ( Get-VAMIServiceAPI -NameFilter "timesync").get()
$timeSyncMode = $timeSync.mode if ($timeSyncMode.mode) {
$timeSyncMode = $timeSync.mode
}
$timeResult = [pscustomobject] @{ $timeResult = [pscustomobject] @{
Timezone = $timeResults.timezone; Timezone = $timeResults.timezone;
@@ -148,13 +157,84 @@ Function Get-VAMITime {
} }
if($timeSyncMode -eq "NTP") { if($timeSyncMode -eq "NTP") {
$ntpServers = (Get-CisService -Name 'com.vmware.appliance.techpreview.ntp').get() $ntpServers = ( Get-VAMIServiceAPI -NameFilter "ntp").get()
$timeResult.NTPServers = $ntpServers.servers if ($ntpServers.servers) {
$timeResult.NTPStatus = $ntpServers.status $timeResult.NTPServers = $ntpServers.servers
$timeResult.NTPStatus = $ntpServers.status
} else {
$timeResult.NTPServers = $ntpServers
$timeResult.NTPStatus = ( Get-VAMIServiceAPI -NameFilter "ntp").test(( Get-VAMIServiceAPI -NameFilter "ntp").get()).status
}
} }
$timeResult $timeResult
} }
Function Set-VAMITimeSync {
<#
.NOTES
===========================================================================
Inspired by: William Lam
Organization: VMware
Blog: www.virtuallyghetto.com
Twitter: @lamw
Created by: Michael Dunsdon
Twitter: @MJDunsdon
Date: September 21, 2020
===========================================================================
.SYNOPSIS
This function sets the time and NTP info from VAMI interface (5480)
for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA.
.DESCRIPTION
Function to return current Time and NTP information
.EXAMPLE
Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Set-VAMITimeSync -SyncMode "NTP" -TimeZone "US/Pacific" -NTPServers "10.0.0.10,10.0.0.11,10.0.0.12"
.NOTES
Create script to Set NTP for Newer VCSA. Script supports 6.7 VCSAs
#>
param(
[Parameter(Mandatory=$true)]
[ValidateSet('Disabled', 'NTP', 'Host')]
[String]$SyncMode,
[Parameter(Mandatory=$False,HelpMessage="TimeZone Name needs to be in Posix Naming / Unix format")]
[String]$TimeZone,
[Parameter(Mandatory=$false,HelpMessage="NTP Servers need to be either a string separated by ',' or an array of servers")]
$NTPServers
)
$timeSyncMode = ( Get-VAMIServiceAPI -NameFilter "timesync").get()
if ($timeSyncMode.gettype().name -eq "PSCustomObject") {
if ($SyncMode.ToUpper() -ne $timeSyncMode.mode.toupper()) {
$timesyncapi = (Get-VAMIServiceAPI -NameFilter "timesync")
$timesyncconfig = $timesyncapi.help.set.config.createexample()
$timesyncconfig = $Sync
$timesyncapi.set($timesyncconfig)
}
} else {
if ($SyncMode.ToUpper() -ne $timeSyncMode.toupper()) {
$timesyncapi = (Get-VAMIServiceAPI -NameFilter "timesync")
$timesyncapi.set($Sync)
}
if ($NTPServers) {
$ntpapi = (Get-VAMIServiceAPI -NameFilter "ntp")
if ($NTPServers.gettype().Name -eq "String") {
$NTPServersArray = ($NTPServers -split ",").trim()
} else {
$NTPServersArray = $NTPServers
}
if ($NTPServersArray -ne $ntpapi.get()) {
$ntpapi.set($NTPServersArray)
}
}
if ($TimeZone) {
$timezoneapi = (Get-VAMIServiceAPI -NameFilter "timezone")
if ($TimeZone -ne ($timezoneapi.get())) {
$timezoneapi.set($TimeZone)
}
}
}
}
Function Get-VAMINetwork { Function Get-VAMINetwork {
<# <#
.NOTES .NOTES
@@ -163,6 +243,9 @@ Function Get-VAMINetwork {
Organization: VMware Organization: VMware
Blog: www.virtuallyghetto.com Blog: www.virtuallyghetto.com
Twitter: @lamw Twitter: @lamw
Modifed by: Michael Dunsdon
Twitter: @MJDunsdon
Date: September 21, 2020
=========================================================================== ===========================================================================
.SYNOPSIS .SYNOPSIS
This function retrieves network information from VAMI interface (5480) This function retrieves network information from VAMI interface (5480)
@@ -172,22 +255,27 @@ Function Get-VAMINetwork {
.EXAMPLE .EXAMPLE
Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VAMINetwork Get-VAMINetwork
.NOTES
Modified script to account for Newer VCSA. Script supports 6.5 and 6.7 VCSAs
#> #>
$netResults = @() $netResults = @()
$Hostname = (Get-CisService -Name 'com.vmware.appliance.networking.dns.hostname').get() $Hostname = ( Get-VAMIServiceAPI -NameFilter "dns.hostname").get()
$dns = (Get-CisService -Name 'com.vmware.appliance.networking.dns.servers').get() $dns = (Get-VAMIServiceAPI -NameFilter "dns.servers").get()
Write-Host "Hostname: " $hostname Write-Host "Hostname: " $hostname
Write-Host "DNS Servers: " $dns.servers Write-Host "DNS Servers: " $dns.servers
$interfaces = (Get-CisService -Name 'com.vmware.appliance.networking.interfaces').list() $interfaces = (Get-VAMIServiceAPI -NameFilter "interfaces").list()
foreach ($interface in $interfaces) { foreach ($interface in $interfaces) {
$ipv4API = (Get-CisService -Name 'com.vmware.appliance.techpreview.networking.ipv4') $ipv4API = (Get-VAMIServiceAPI -NameFilter "ipv4")
$spec = $ipv4API.Help.get.interfaces.CreateExample() if ($ipv4API.help.get.psobject.properties.name -like "*_*") {
$spec+= $interface.name $ipv4result = $ipv4API.get($interface.Name)
$ipv4result = $ipv4API.get($spec) $Updateable = $ipv4result.configurable
} else {
$ipv4result = $ipv4API.get(@($interface.Name))
$Updateable = $ipv4result.updateable
}
$interfaceResult = [pscustomobject] @{ $interfaceResult = [pscustomobject] @{
Inteface = $interface.name; Inteface = $interface.name;
MAC = $interface.mac; MAC = $interface.mac;
@@ -196,7 +284,7 @@ Function Get-VAMINetwork {
IP = $ipv4result.address; IP = $ipv4result.address;
Prefix = $ipv4result.prefix; Prefix = $ipv4result.prefix;
Gateway = $ipv4result.default_gateway; Gateway = $ipv4result.default_gateway;
Updateable = $ipv4result.updateable Updateable = $Updateable
} }
$netResults += $interfaceResult $netResults += $interfaceResult
} }
@@ -286,6 +374,9 @@ Function Get-VAMIStorageUsed {
Organization: VMware Organization: VMware
Blog: www.virtuallyghetto.com Blog: www.virtuallyghetto.com
Twitter: @lamw Twitter: @lamw
Modifed by: Michael Dunsdon
Twitter: @MJDunsdon
Date: September 16, 2020
=========================================================================== ===========================================================================
.SYNOPSIS .SYNOPSIS
This function retrieves the individaul OS partition storage utilization This function retrieves the individaul OS partition storage utilization
@@ -295,70 +386,49 @@ Function Get-VAMIStorageUsed {
.EXAMPLE .EXAMPLE
Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VAMIStorageUsed Get-VAMIStorageUsed
.NOTES
Modified script to account for Newer VCSA. Script supports 6.5 and 6.7 VCSAs.
Also modifed the static list of filesystems to be more dynamic in nature to account for the differences in VCSA versions.
#> #>
$monitoringAPI = Get-CisService 'com.vmware.appliance.monitoring' $monitoringAPI = Get-CisService 'com.vmware.appliance.monitoring'
$querySpec = $monitoringAPI.help.query.item.CreateExample() $querySpec = $monitoringAPI.help.query.item.CreateExample()
# List of IDs from Get-VAMIStatsList to query # List of IDs from Get-VAMIStatsList to query
$querySpec.Names = @( $querySpec.Names = ($monitoringAPI.list() | Where-Object {($_.name -like "*storage.used.filesystem*") -or ($_.name -like "*storage.totalsize.filesystem*") } | Select-Object id | Sort-Object -Property id).id.value
"storage.used.filesystem.autodeploy",
"storage.used.filesystem.boot",
"storage.used.filesystem.coredump",
"storage.used.filesystem.imagebuilder",
"storage.used.filesystem.invsvc",
"storage.used.filesystem.log",
"storage.used.filesystem.netdump",
"storage.used.filesystem.root",
"storage.used.filesystem.updatemgr",
"storage.used.filesystem.vcdb_core_inventory",
"storage.used.filesystem.vcdb_seat",
"storage.used.filesystem.vcdb_transaction_log",
"storage.totalsize.filesystem.autodeploy",
"storage.totalsize.filesystem.boot",
"storage.totalsize.filesystem.coredump",
"storage.totalsize.filesystem.imagebuilder",
"storage.totalsize.filesystem.invsvc",
"storage.totalsize.filesystem.log",
"storage.totalsize.filesystem.netdump",
"storage.totalsize.filesystem.root",
"storage.totalsize.filesystem.updatemgr",
"storage.totalsize.filesystem.vcdb_core_inventory",
"storage.totalsize.filesystem.vcdb_seat",
"storage.totalsize.filesystem.vcdb_transaction_log"
)
# Tuple (Filesystem Name, Used, Total) to store results # Tuple (Filesystem Name, Used, Total) to store results
$storageStats = @{ $storageStats = @{
"archive"=@{"name"="/storage/archive";"used"=0;"total"=0};
"autodeploy"=@{"name"="/storage/autodeploy";"used"=0;"total"=0}; "autodeploy"=@{"name"="/storage/autodeploy";"used"=0;"total"=0};
"boot"=@{"name"="/boot";"used"=0;"total"=0}; "boot"=@{"name"="/boot";"used"=0;"total"=0};
"coredump"=@{"name"="/storage/core";"used"=0;"total"=0}; "core"=@{"name"="/storage/core";"used"=0;"total"=0};
"imagebuilder"=@{"name"="/storage/imagebuilder";"used"=0;"total"=0}; "imagebuilder"=@{"name"="/storage/imagebuilder";"used"=0;"total"=0};
"invsvc"=@{"name"="/storage/invsvc";"used"=0;"total"=0}; "invsvc"=@{"name"="/storage/invsvc";"used"=0;"total"=0};
"log"=@{"name"="/storage/log";"used"=0;"total"=0}; "log"=@{"name"="/storage/log";"used"=0;"total"=0};
"netdump"=@{"name"="/storage/netdump";"used"=0;"total"=0}; "netdump"=@{"name"="/storage/netdump";"used"=0;"total"=0};
"root"=@{"name"="/";"used"=0;"total"=0}; "root"=@{"name"="/";"used"=0;"total"=0};
"updatemgr"=@{"name"="/storage/updatemgr";"used"=0;"total"=0}; "updatemgr"=@{"name"="/storage/updatemgr";"used"=0;"total"=0};
"vcdb_core_inventory"=@{"name"="/storage/db";"used"=0;"total"=0}; "db"=@{"name"="/storage/db";"used"=0;"total"=0};
"vcdb_seat"=@{"name"="/storage/seat";"used"=0;"total"=0}; "seat"=@{"name"="/storage/seat";"used"=0;"total"=0};
"vcdb_transaction_log"=@{"name"="/storage/dblog";"used"=0;"total"=0} "dblog"=@{"name"="/storage/dblog";"used"=0;"total"=0};
"swap"=@{"name"="swap";"used"=0;"total"=0}
} }
$querySpec.interval = "DAY1" $querySpec.interval = "DAY1"
$querySpec.function = "MAX" $querySpec.function = "MAX"
$querySpec.start_time = ((get-date).AddDays(-1)) $querySpec.start_time = ((Get-Date).AddDays(-1))
$querySpec.end_time = (Get-Date) $querySpec.end_time = (Get-Date)
$queryResults = $monitoringAPI.query($querySpec) | Select * -ExcludeProperty Help $queryResults = $monitoringAPI.query($querySpec) | Select-Object * -ExcludeProperty Help
foreach ($queryResult in $queryResults) { foreach ($queryResult in $queryResults) {
# Update hash if its used storage results # Update hash if its used storage results
$key = ((($queryResult.name).toString()).split(".")[-1]) -replace "coredump","core" -replace "vcdb_","" -replace "core_inventory","db" -replace "transaction_log","dblog"
$value = [Math]::Round([int]($queryResult.data[1]).toString()/1MB,2)
if($queryResult.name -match "used") { if($queryResult.name -match "used") {
$key = (($queryResult.name).toString()).split(".")[-1]
$value = [Math]::Round([int]($queryResult.data[1]).toString()/1MB,2)
$storageStats[$key]["used"] = $value $storageStats[$key]["used"] = $value
# Update hash if its total storage results # Update hash if its total storage results
} else { } else {
$key = (($queryResult.name).toString()).split(".")[-1]
$value = [Math]::Round([int]($queryResult.data[1]).toString()/1MB,2)
$storageStats[$key]["total"] = $value $storageStats[$key]["total"] = $value
} }
} }
@@ -406,7 +476,6 @@ Function Get-VAMIService {
if($Name -ne "") { if($Name -ne "") {
$vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service' $vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service'
try { try {
$serviceStatus = $vMonAPI.get($name,0) $serviceStatus = $vMonAPI.get($name,0)
$serviceString = [pscustomobject] @{ $serviceString = [pscustomobject] @{
@@ -423,7 +492,6 @@ Function Get-VAMIService {
} else { } else {
$vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service' $vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service'
$services = $vMonAPI.list_details() $services = $vMonAPI.list_details()
$serviceResult = @() $serviceResult = @()
foreach ($key in $services.keys | Sort-Object -Property Value) { foreach ($key in $services.keys | Sort-Object -Property Value) {
$serviceString = [pscustomobject] @{ $serviceString = [pscustomobject] @{
@@ -448,7 +516,7 @@ Function Start-VAMIService {
Organization: VMware Organization: VMware
Blog: www.virtuallyghetto.com Blog: www.virtuallyghetto.com
Twitter: @lamw Twitter: @lamw
=========================================================================== ===========================================================================
.SYNOPSIS .SYNOPSIS
This function retrieves list of services in VAMI interface (5480) This function retrieves list of services in VAMI interface (5480)
for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA.
@@ -470,8 +538,8 @@ Function Start-VAMIService {
$vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service' $vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service'
try { try {
Write-Host "Starting $name service ..." Write-Host "Starting $Name service ..."
$vMonAPI.start($name) $vMonAPI.start($Name)
} catch { } catch {
Write-Error $Error[0].exception.Message Write-Error $Error[0].exception.Message
} }
@@ -507,8 +575,8 @@ Function Stop-VAMIService {
$vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service' $vMonAPI = Get-CisService 'com.vmware.appliance.vmon.service'
try { try {
Write-Host "Stopping $name service ..." Write-Host "Stopping $Name service ..."
$vMonAPI.stop($name) $vMonAPI.stop($Name)
} catch { } catch {
Write-Error $Error[0].exception.Message Write-Error $Error[0].exception.Message
} }
@@ -556,15 +624,20 @@ Function Get-VAMIUser {
Organization: VMware Organization: VMware
Blog: www.virtuallyghetto.com Blog: www.virtuallyghetto.com
Twitter: @lamw Twitter: @lamw
=========================================================================== Modifed by: Michael Dunsdon
.SYNOPSIS Twitter: @MJDunsdon
This function retrieves VAMI local users using VAMI interface (5480) Date: September 16, 2020
===========================================================================
.SYNOPSIS
This function retrieves VAMI local users using VAMI interface (5480)
for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA.
.DESCRIPTION .DESCRIPTION
Function to retrieve VAMI local users Function to retrieve VAMI local users
.EXAMPLE .EXAMPLE
Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VAMIUser Get-VAMIUser
.NOTES
Modified script to account for Newer VCSA. Script supports 6.5 and 6.7 VCSAs.
#> #>
param( param(
[Parameter( [Parameter(
@@ -575,42 +648,47 @@ Function Get-VAMIUser {
[String]$Name [String]$Name
) )
$userAPI = Get-CisService 'com.vmware.appliance.techpreview.localaccounts.user' $userAPI = Get-VAMIServiceAPI -NameFilter "accounts"
$UserResults = @()
$userResults = @() if (($Name -ne "") -and ($null -ne $Name)) {
if($Name -ne "") {
try { try {
$user = $userAPI.get($name) $Users = $UserAPI.get($name)
$userString = [pscustomobject] @{
User = $user.username
Name = $user.fullname
Email = $user.email
Status = $user.status
PasswordStatus = $user.passwordstatus
Role = $user.role
}
$userResults += $userString
} catch { } catch {
Write-Error $Error[0].exception.Message Write-Error $Error[0].exception.Message
} }
} else { } else {
$users = $userAPI.list() $Users = $UserAPI.list()
}
foreach ($user in $users) { if ($Users.status) {
$userString = [pscustomobject] @{ foreach ($User in $Users) {
User = $user.username $UserString = [pscustomobject] @{
Name = $user.fullname User = $User.username
Email = $user.email Name = $User.fullname
Status = $user.status Email = $User.email
PasswordStatus = $user.passwordstatus Status = $User.status
Role = $user.role PasswordStatus = $User.passwordstatus
Roles = @($User.role)
} }
$userResults += $userString $UserResults += $UserString
}
} else {
foreach ($User in $Users) {
$UserInfo = $userAPI.get($user)
$UserString = [pscustomobject] @{
User = $User.value
Name = $UserInfo.fullname
Email = $UserInfo.email
Status = $UserInfo.enabled
LastPasswordChange = $UserInfo.last_password_change
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"}
Roles = $UserInfo.roles
}
$UserResults += $UserString
} }
} }
$userResults $UserResults
} }
Function New-VAMIUser { Function New-VAMIUser {
@@ -621,53 +699,144 @@ Function New-VAMIUser {
Organization: VMware Organization: VMware
Blog: www.virtuallyghetto.com Blog: www.virtuallyghetto.com
Twitter: @lamw Twitter: @lamw
=========================================================================== Modifed by: Michael Dunsdon
.SYNOPSIS Twitter: @MJDunsdon
This function to create new VAMI local user using VAMI interface (5480) Date: September 16, 2020
===========================================================================
.SYNOPSIS
This function to create new VAMI local user using VAMI interface (5480)
for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA.
.DESCRIPTION .DESCRIPTION
Function to create a new VAMI local user Function to create a new VAMI local user
.EXAMPLE .EXAMPLE
Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
New-VAMIUser -name lamw -fullname "William Lam" -role "operator" -email "lamw@virtuallyghetto.com" -password "VMware1!" New-VAMIUser -name lamw -fullname "William Lam" -role "operator" -email "lamw@virtuallyghetto.com" -password "VMware1!" -passwordexpires -passwordexpiresat "1/1/1970" -maxpasswordage 90
.NOTES
Modified script to account for Newer VCSA. Script supports 6.5 and 6.7 VCSAs.
Also added new Parameters to script.
#> #>
param( param(
[Parameter( [Parameter(Mandatory=$true)]
Mandatory=$true) [String]$Name,
] [Parameter(Mandatory=$true)]
[String]$name, [String]$FullName,
[Parameter( [Parameter(Mandatory=$true)]
Mandatory=$true) [ValidateSet("admin","operator","superAdmin")]
] [String]$Role,
[String]$fullname, [Parameter(Mandatory=$false)]
[Parameter( [String]$Email="",
Mandatory=$true) [Parameter(Mandatory=$true)]
] [String]$Password,
[ValidateSet("admin","operator","superAdmin")][String]$role, [Parameter(Mandatory=$false)]
[Parameter( [switch]$PasswordExpires,
Mandatory=$false) [Parameter(Mandatory=$false)]
] [String]$PasswordExpiresAt = $null,
[String]$email="", [Parameter(Mandatory=$false)]
[Parameter( [String]$MaxPasswordAge = 90
Mandatory=$true)
]
[String]$password
) )
$userAPI = Get-CisService 'com.vmware.appliance.techpreview.localaccounts.user' $userAPI = Get-VAMIServiceAPI -NameFilter "accounts"
$createSpec = $userAPI.Help.add.config.CreateExample() if ($userAPI.name -eq 'com.vmware.appliance.techpreview.localaccounts.user') {
$CreateSpec = $UserAPI.Help.add.config.CreateExample()
} else {
$CreateSpec = $UserAPI.Help.create.config.CreateExample()
}
$createSpec.username = $name $CreateSpec.fullname = $FullName
$createSpec.fullname = $fullname $CreateSpec.role = $Role
$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
try { if ($CreateSpec.psobject.properties.name -contains "username") {
Write-Host "Creating new user $name ..." $CreateSpec.username = $Name
$userAPI.add($createSpec) try {
} catch { Write-Host "Creating new user $Name ..."
Write-Error $Error[0].exception.Message $UserAPI.add($CreateSpec)
} catch {
Write-Error $Error[0].exception.Message
}
} else {
$CreateSpec.password_expires = $PasswordExpires
$CreateSpec.password_expires_at = $PasswordExpiresAt
$CreateSpec.max_days_between_password_change = $MaxPasswordAge
try {
Write-Host "Creating new user $Name ..."
$UserAPI.create($Name, $CreateSpec)
} catch {
Write-Error $Error[0].exception.Message
}
}
}
Function Update-VAMIUser {
<#
.NOTES
===========================================================================
Inspired by: William Lam
Organization: VMware
Blog: www.virtuallyghetto.com
Twitter: @lamw
Created by: Michael Dunsdon
Twitter: @MJDunsdon
Date: September 21, 2020
===========================================================================
.SYNOPSIS
This function to update fields of a VAMI local user using VAMI interface (5480)
for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA.
.DESCRIPTION
Function to update fields of a VAMI local user
.EXAMPLE
Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Update-VAMIUser -name lamw -fullname "William Lam" -role "operator" -email "lamw@virtuallyghetto.com" -password "VMware1!" -passwordexpires -passwordexpiresat "1/1/1970" -maxpasswordage 90
.NOTES
Created script to allow updating of an exisiting user account. Script supports 6.5 and 6.7 VCSAs.
#>
param(
[Parameter(Mandatory=$true)]
[String]$Name,
[Parameter(Mandatory=$false)]
[String]$FullName,
[Parameter(Mandatory=$false)]
[ValidateSet("admin","operator","superAdmin")]
[String]$Role,
[Parameter(Mandatory=$false)]
[String]$Email="",
[Parameter(Mandatory=$false)]
[String]$Password = $null,
[Parameter(Mandatory=$false)]
[switch]$PasswordExpires,
[Parameter(Mandatory=$false)]
[String]$PasswordExpiresAt = $null,
[Parameter(Mandatory=$false)]
[String]$MaxPasswordAge = 90
)
$userAPI = Get-VAMIServiceAPI -NameFilter "accounts"
$UpdateSpec = $UserAPI.Help.set.config.CreateExample()
$UpdateSpec.fullname = $FullName
$UpdateSpec.role = $Role
$UpdateSpec.email = $Email
if ($UpdateSpec.psobject.properties.name -contains "username") {
$UpdateSpec.username = $Name
try {
Write-Host "Updating Settings for user $Name ..."
$UserAPI.set($UpdateSpec)
} catch {
Write-Error $Error[0].exception.Message
}
} else {
$UpdateSpec.password = [VMware.VimAutomation.Cis.Core.Types.V1.Secret]$Password
$UpdateSpec.password_expires = $PasswordExpires
$UpdateSpec.password_expires_at = $PasswordExpiresAt
$UpdateSpec.max_days_between_password_change = $MaxPasswordAge
try {
Write-Host "Updating Settings for user $Name ..."
$UserAPI.update($Name, $UpdateSpec)
} catch {
Write-Error $Error[0].exception.Message
}
} }
} }
@@ -679,32 +848,30 @@ Function Remove-VAMIUser {
Organization: VMware Organization: VMware
Blog: www.virtuallyghetto.com Blog: www.virtuallyghetto.com
Twitter: @lamw Twitter: @lamw
=========================================================================== Modifed by: Michael Dunsdon
.SYNOPSIS Twitter: @MJDunsdon
This function to remove VAMI local user using VAMI interface (5480) Date: September 21, 2020
===========================================================================
.SYNOPSIS
This function to remove VAMI local user using VAMI interface (5480)
for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA. for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA.
.DESCRIPTION .DESCRIPTION
Function to remove VAMI local user Function to remove VAMI local user
.EXAMPLE .EXAMPLE
Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VAMIAccess Get-VAMIAccess
.NOTES
Modified script to account for Newer VCSA. Script supports 6.5 and 6.7 VCSAs.
#> #>
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
param( param(
[Parameter( [Parameter(Mandatory=$true)]
Mandatory=$true) [String]$Name
]
[String]$name,
[Parameter(
Mandatory=$false)
]
[boolean]$confirm=$false
) )
Begin {}
if(!$confirm) { Process{
$answer = Read-Host -Prompt "Do you want to delete user $name (Y or N)" if($PSCmdlet.ShouldProcess($Name,'Delete')) {
if($answer -eq "Y" -or $answer -eq "y") { $userAPI = Get-VAMIServiceAPI -NameFilter "accounts"
$userAPI = Get-CisService 'com.vmware.appliance.techpreview.localaccounts.user'
try { try {
Write-Host "Deleting user $name ..." Write-Host "Deleting user $name ..."
$userAPI.delete($name) $userAPI.delete($name)
@@ -713,4 +880,41 @@ Function Remove-VAMIUser {
} }
} }
} }
End{}
}
Function Get-VAMIServiceAPI {
<#
.NOTES
===========================================================================
Inspired by: William Lam
Organization: VMware
Blog: www.virtuallyghetto.com
Twitter: @lamw
Created by: Michael Dunsdon
Twitter: @MJDunsdon
Date: September 21, 2020
===========================================================================
.SYNOPSIS
This function returns the Service Api Based on a String of Service Name.
.DESCRIPTION
Function to find and get service api based on service name string
.EXAMPLE
Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VAMIUser -NameFilter "accounts"
.NOTES
Script supports 6.5 and 6.7 VCSAs.
Function Gets all Service Api Names and filters the list based on NameFilter
If Multiple Serivces are returned it takes the Top one.
#>
param(
[Parameter(Mandatory=$true)]
[String]$NameFilter
)
$ServiceAPI = Get-CisService | Where-Object {$_.name -like "*$($NameFilter)*"}
if (($ServiceAPI.count -gt 1) -and $NameFilter) {
$ServiceAPI = ($ServiceAPI | Sort-Object -Property Name)[0]
}
return $ServiceAPI
} }