Active IQ Unified Manager Discussions

WFA error message when creating new command

Jim_Robertson
6,248 Views

I am trying to create a simple Powershell command in WFA to create a Unix user (this is my first attempt at creating my own command, so please bear with me).  I have created a Powershell script that runs fine from Powershell (minus the WFALogger commands), but when I copy the same script into a WFA command and run a test against it, I get the following error:

 

13:57:29.844 INFO  [Create Unix User] ### Command 'Create Unix User' in 'POWER_SHELL' ###
13:57:31.766 INFO  [Create Unix User] Using cached cluster connection
13:57:32.094 ERROR  [Create Unix User] Cannot bind argument to parameter 'FilterScript' because it is null.
13:57:32.219 ERROR  [Create Unix User] Failed executing command. Exception: Cannot bind argument to parameter 'FilterScript' because it is null.

 

 

The script checks for an existing account.  If one exists, it errors out.  If none exists, it sets the UID to 10000.  If a different account already exists, it increments to the the previous UID + 1:

param (
  [parameter(Mandatory=$true, HelpMessage="Cluster address")]
  [string]$Cluster,
  
  [parameter(Mandatory=$true, HelpMessage="Storage Virtual Machine name")]
  [string]$VserverName,
  
  [parameter(Mandatory=$true, HelpMessage="Name of the Unix server to be created")]
  [string]$UnixServer
)

# connect to cluster
Connect-WFACluster $Cluster

$UnixServer = $UnixServer.ToUpper() + "$"

$FindServer = Get-NcNameMappingUnixUser -Name $UnixServer -VserverContext $VServerName

if ($FindServer.UserName -eq $UnixServer)
{
   Get-WFALogger -Info -message $("Unix account for server '" + $UnixServer + "' on Storage Virtual Machine '" + $VserverName + "' already exists'")
}

else
{
    $UnixAccounts = Get-NcNameMappingUnixUser -Name L* -VserverContext $VServerName
    if ($UnixAccounts -eq $NULL)
    {
        [int]$NextUID = 10000
    }
    else
    {
        $UserIDs = $UnixAccounts.UserId
        $UserIDs = $UserIDs | measure -Maximum
        if ($UserIDs.Maximum -lt 10000)
        {
            [int]$NextUID = 10000
        }
        else
        { 
            [int]$NextUID = $UserIDs.Maximum + 1
        }
    }

#    Get-WFALogger -Info -message $("Creating Unix account for server '" + $UnixServer + "' on Storage Virtual Machine '" + $VserverName + "'")
    $expression = "New-NcNameMappingUnixUser -Name $UnixServer -UserId $NextUID -GroupId 65534 -VserverContext $VServerName"
    Invoke-Expression -ErrorAction Stop $expression
}

 

 

 


Any idea what I'm doing wrong?

1 ACCEPTED SOLUTION

mbeattie
6,136 Views

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.

View solution in original post

5 REPLIES 5

sundarea
6,219 Views

Hi Jim_Robertson,

 

 

Please remove the last single quote in Get-WFALoggers. The single quote is not matching

 

 

Get-WFALogger -Info -message $("Unix account for server '" + $UnixServer + "' on Storage Virtual Machine '" + $VserverName + "' already exists'")

 

Regards,

Sundar

mbeattie
6,204 Views

Hi Jim,

 

When coding WFA commands it can be useful when testing to troubleshoot your code externally to WFA. Check this out:

 

http://www.wfaguy.com/2017/08/debug-wfa-in-your-powershell-editor.html

 

This is a useful technique to help determine if it's a WFA problem or PowerShell coding issue

 

Looking at your code, here a few "general" suggestions (which i certainly wish were more consistently adopted for WFA Certified Content)

 

  • Create commands as strings then invoke the commands as expressions. This ensures you can log the command which is useful for troubleshooting (and change control)
  • Use comments in code within blocks (It will help you when you revisit your code or someone else has to read what you've written)
  • Always use error checking (try\catch) whenever executing any command
  • Always implement logging and error logging to ensure you capture the error message for troubleshooting.

With that said, here is an updated version of you code (Note I haven't tested it) but you'll get the idea.

Please let me know if you have any questions

 

Note: If you run this, download the logs then do a 'find /i "Executed Command" *.log | clip" and paste it into notepad...an easy method to provide a run sheet for your RFC.

 

Hope this helps

 

/Matt

 

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
)
#'------------------------------------------------------------------------------
#'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""" } } #'------------------------------------------------------------------------------

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Jim_Robertson
6,155 Views

@sundarea, I tried just commenting out the entire WFALogger line, and I'm still getting the same error message, so I don't think that's it.

 

 

@mbeattie, thank you very much for the detailed response!  I did try your code, but when I run a test from WFA, I am getting different errors.  But, hopefully you can teach me how to fish here 🙂  I am familiar with the WFA Guy Blog.  I attended one of his session at Insight in Las Vegas last month, and it was fantastic.  I have been trying to get time to go through more of the blog, but have been struggling with this instead.

I did attempt to do the WFA debugging as indicated in the blog, but I'm getting a ton of errors that don't make any sense to me.  I actually left a reply on his blog a few days ago, but if you're familiar with how it works, maybe you can help (and help others in the process!).

This is what I posted on the blog:

 

I tried to run this, and I'm getting errors just trying to run the ".\profile.ps1". Any idea what I'm doing wrong? I have WFA installed to my E: drive, but the profile script seems to account for that.

It spits out a ton of errors, but they are all similar to this:
Import-Module : The following error occurred while loading the extended type data file: , E:\Program Files\NetApp\WFA\PoSH\Modules\DataONTAP\DataONTAP.Type.ps1xml(1376) : Error in type "DataONTAP.Types.Iscsi.IscsiPortalListEntryInfo": The "Type" node must have "Members", "TypeConverters", or "TypeAdapters".

E:\Program Files\NetApp\WFA\PoSH\Modules\DataONTAP\DataONTAP.Type.ps1xml(1367) : Error in type "DataONTAP.PowerShell.SDK.Cmdlets.HyperV.MbrPartition": The "Type" node must have "Members", "TypeConverters", or "TypeAdapters".

 

 Thanks for all your help!

mbeattie
6,137 Views

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.

sinhaa
6,118 Views

@Jim_Robertson @mbeattie

 

 

To Aid your Debugging powershell code in WFA, use this : Debugging powershell code in WFA: The First Aid

 

 

sinhaa

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
Public