Hi Jim,
I debugged the code for you, looks like i'd missed quotes around the command in code i'd previously posted:
#'------------------------------------------------------------------------------
#'Enumerate the UNIX user mapping for the server.
#'------------------------------------------------------------------------------
[String]$command = Get-NcNameMappingUnixUser -Name $UnixServer -VserverContext $VServerName -ErrorAction Stop
Here is example output of how i tested it externally to WFA in my lab using a powershell script.
PS C:\> cd C:\Scripts\PowerShell\Projects\WFA\SetUserMapping
PS C:\Scripts\PowerShell\Projects\WFA\SetUserMapping> .\SetUserMapping.ps1 -Cluster cluster1 -VserverName vserver2 -UnixServer LINUX01
Enumerated WFA installation Path from Registry key "hklm:\system\currentcontrolset\services\na_wfa_srv" as "C:\Program Files\NetApp\WFA"
Loading WFA profile
Executed Command: Connect-NcController -Name cluster1 -HTTPS -Credential $credentials -ErrorAction Stop
Connected to cluster "cluster1"
Executed Command: Get-NcNameMappingUnixUser -Name LINUX01$ -VserverContext vserver2 -ErrorAction Stop
Enumerated UNIX user mapping for server "LINUX01$" on vserver "vserver2"
Executed Command: Get-NcNameMappingUnixUser -Name L* -VserverContext vserver2 -ErrorAction Stop
Enumerated UNIX user mapping for server "L*" on vserver "vserver2"
UserName UserId GroupId Vserver FullName
-------- ------ ------- ------- --------
LINUX01$ 10000 65534 vserver2
Executed Command: New-NcNameMappingUnixUser -Name LINUX01$ -UserId 10000 -GroupId 65534 -VserverContext vserver2 -ErrorAction Stop
Created user mapping for server "LINUX01$" UserID "10000" GroupID "65534" on vserver "vserver2"
PS C:\Scripts\PowerShell\Projects\WFA\SetUserMapping>
I tested it a few times just to make sure it increments the UserID for the host by incrementing 10K + 1. Works fine. Here is the source code for the above script:
Param(
[Parameter(Mandatory=$True, HelpMessage="The Cluster name or IP Address")]
[String]$Cluster,
[Parameter(Mandatory=$True, HelpMessage="The vserver name")]
[String]$VserverName,
[Parameter(Mandatory=$True, HelpMessage="The Unix server name to be created")]
[String]$UnixServer
)
#'------------------------------------------------------------------------------
Function Get-WFALogger{
Param(
[Switch]$Info,
[Switch]$Error,
[Switch]$Warn,
[String]$Message
)
If($Info){
Write-Host $Message -foregroundColor green
}
If($Warn){
Write-Host $Message -ForegroundColor yellow
}
If($Error){
Write-Host $Message -ForegroundColor red
}
}
#'------------------------------------------------------------------------------
Function Connect-WfaCluster{
Param(
[Parameter(Mandatory=$True, HelpMessage="The Cluster name or IP Address")]
[String]$Node,
[Parameter(Mandatory=$False, HelpMessage="The vserver name")]
[String]$Vserver
)
$credentials = Get-Credential -Credential admin
If($Vserver){
[String]$command = "Connect-NcController -Name $Node -HTTPS -Credential `$credentials -Vserver $Vserver -ErrorAction Stop"
}Else{
[String]$command = "Connect-NcController -Name $Node -HTTPS -Credential `$credentials -ErrorAction Stop"
}
Try{
Invoke-Expression -Command $command -ErrorAction Stop | Out-Null
Get-WFALogger -Info -Message "Executed Command`: $command"
If($Vserver){
Get-WFALogger -Info -Message "Connected to cluster ""$Node"" vserver ""$Vserver"""
}Else{
Get-WFALogger -Info -Message "Connected to cluster ""$Node"""
}
}Catch{
Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
If($Vserver){
Throw "Failed connecting to cluster ""$Node"" vserver ""$Vserver"""
}Else{
Throw "Failed connecting to cluster ""$Node"""
}
}
}
#'------------------------------------------------------------------------------
#'Initialization Section
#'------------------------------------------------------------------------------
[String]$scriptPath = Split-Path($MyInvocation.MyCommand.Path)
[String]$scriptSpec = $MyInvocation.MyCommand.Definition
[String]$scriptBaseName = (Get-Item $scriptSpec).BaseName
[String]$scriptName = (Get-Item $scriptSpec).Name
#'------------------------------------------------------------------------------
#'Enumerate the WFA install path from the registry
#'------------------------------------------------------------------------------
[String]$registryPath = "hklm:\system\currentcontrolset\services\na_wfa_srv";
Try{
[System.Object]$result = Get-ItemProperty -Path $registryPath -ErrorAction Stop
[String]$wfaExeSpec = $result.ImagePath.Split("/")[0].Trim() -Replace("""", "")
[String]$wfaServicePath = $wfaExeSpec.SubString(0, $wfaExeSpec.LastIndexOf("\"))
[String]$installPath = $wfaServicePath.SubString(0, $wfaServicePath.LastIndexOf("\"))
[Bool]$wfaInstalled = $False
If($installPath -ne $Null){
[Bool]$wfaInstalled = $True
Get-WFALogger -Info -Message "Enumerated WFA installation Path from Registry key ""$registryPath"" as ""$installPath"""
}
}Catch{
Get-WFALogger -Info -Message "WFA is not installed. Importing DataONTAP PowerShell module"
}
#'------------------------------------------------------------------------------
Try{
If($wfaInstalled){
Set-Location "$installPath\PoSH\"
Get-WFALogger -Info -Message "Loading WFA profile"
. '.\profile.ps1'
}Else{
Import-Module DataONTAP -ErrorAction Stop
}
}Catch{
If($wfaInstalled){
Throw "Failed loading WFA profile ""$installPath\PoSH\profile.ps1"""
}Else{
Throw "Failed importing DataONTAP PowerShell module"
}
}
Set-Location $scriptPath
#'------------------------------------------------------------------------------
#'Connect to the cluster
#'------------------------------------------------------------------------------
Connect-WFACluster $Cluster
#'------------------------------------------------------------------------------
#'Ensure the UNIX server ends with a '$' character.
#'------------------------------------------------------------------------------
If(-Not($UnixServer.EndsWith("`$"))){
[String]$UnixServer = $($UnixServer.ToUpper() + "`$")
}
#'------------------------------------------------------------------------------
#'Enumerate the UNIX user mapping for the server.
#'------------------------------------------------------------------------------
[String]$command = "Get-NcNameMappingUnixUser -Name $UnixServer -VserverContext $VServerName -ErrorAction Stop"
Try{
$result = Invoke-Expression -Command $command -ErrorAction Stop
Get-WFALogger -Info -Message "Executed Command`: $command"
Get-WFALogger -Info -Message "Enumerated UNIX user mapping for server ""$UnixServer"" on vserver ""$VserverName"""
}Catch{
Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
Throw "Failed enumerating UNIX user mapping for server ""$UnixServer"" on vserver ""$VserverName"""
}
#'------------------------------------------------------------------------------
#'Ensure the UNIX user mapping is created.
#'------------------------------------------------------------------------------
If($result.UserName -eq $UnixServer){
Get-WFALogger -Info -Message "Unix account for server ""$UnixServer"" on ""$VserverName"" already exists"
}Else{
[String]$command = "Get-NcNameMappingUnixUser -Name L`* -VserverContext $VServerName -ErrorAction Stop"
Try{
$result = Invoke-Expression -Command $command -ErrorAction Stop
Get-WFALogger -Info -Message "Executed Command`: $command"
Get-WFALogger -Info -Message "Enumerated UNIX user mapping for server ""L`*"" on vserver ""$VserverName"""
}Catch{
Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
Throw "Failed enumerating UNIX user mapping for server ""L`*"" on vserver ""$VserverName"""
}
#'---------------------------------------------------------------------------
#'Set the UNIX user mapping UID to 10000 if it doesn't exist otherwise increment.
#'---------------------------------------------------------------------------
If($result -eq $Null){
[Int]$NextUID = 10000
}Else{
$UserIDs = $result.UserId
$UserIDs = $UserIDs | Measure -Maximum
If($UserIDs.Maximum -lt 10000){
[Int]$NextUID = 10000
}Else{
[Int]$NextUID = $($UserIDs.Maximum + 1)
}
}
[Int]$GroupID = 65534
[String]$command = "New-NcNameMappingUnixUser -Name $UnixServer -UserId $NextUID -GroupId $GroupID -VserverContext $VServerName -ErrorAction Stop"
#'---------------------------------------------------------------------------
#'Create the UNIX user mapping.
#'---------------------------------------------------------------------------
Try{
Invoke-Expression -Command $command -ErrorAction Stop
Get-WFALogger -Info -Message "Executed Command`: $command"
Get-WFALogger -Info -Message "Created user mapping for server ""$UnixServer"" UserID ""$NextUID"" GroupID ""$GroupID"" on vserver ""$VserverName"""
}Catch{
Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
Throw "Failed creating UNIX user mapping for server ""$UnixServer"" UserID ""$NextUID"" GroupID ""$GroupID"" on vserver ""$VserverName"""
}
}
#'------------------------------------------------------------------------------
Hope that helps
/Matt
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.