Microsoft Virtualization Discussions

How can I process Warning or Error messages from Invoke-NaSsh


I'm using the cmdlet Invoke-NaSsh to issue ontap commands that don't have an API call. In this case I want to apply fsecurity configs to a volume. So far I was not able to get the warning or error message that is displayed in the powershell console into a variable. I'd like to check if the command throwed an error. Any help is highly appreciated. I attach the scrit and the console output. Thanks in advance.

Import-Module DataONTAP

$napasswd    = "p@assw0rd"        # Password for the Hosting-Filer, the VFiler and the AD Administrator User

$nahost        = "g100bpmc002.g100.intern"        # Name of the Hosting Filer

$navfiler    = "v998spnvv1999gl"        # Name of the VFiler (also the NetBIOS Name of the VFiler)

$filename    = "aclg999l.conf"

$napath        = "/vol/" + $navfiler + "/" + $filename

$filedata    = "cb56f6f4"

$volname    = "g999_filelight_001"

$command    = "vfiler run " + $navfiler + " fsecurity apply " + $napath

#$command    = "vfiler run " + $navfiler + " cifs shares"

Invoke-NaSsh -Controller $nahost -Command $command -Cred wfauser

PS D:\wfa> .\Test_Invoke-NaSsh.ps1

===== v998spnvv1999gl

WARNUNG: fsecurity: /vol/v998spnvv1999gl/aclg999l.conf (Line 2): Unable to parse the security SDDL string.

fsecurity: /vol/v998spnvv1999gl/aclg999l.conf (Line 3): Unable to parse the security SDDL string.

fsecurity: Unable to parse the definition file, quitting.



Stefan, you can use PowerShell's error handling for that.  See 'help about_commonparameters'.

For example, you can capture warnings like this:

PS C:\> Invoke-NaSsh asdf -WarningVariable warn

WARNING: asdf not found.  Type '?' for a list of commands

PS C:\> $warn[0] | fl

Message               : asdf not found.  Type '?' for a list of commands

InvocationInfo        : System.Management.Automation.InvocationInfo

PipelineIterationInfo : {0, 1}

If you want your script to stop execution if you get a warning, that's easy too:

PS C:\> Invoke-NaSsh asdf -WarningVariable warn -WarningAction stop

WARNING: asdf not found.  Type '?' for a list of commands

Invoke-NaSsh : Command execution stopped because the preference variable "WarningPreference" or common parameter is set to Stop.

At line:1 char:13

+ invoke-nassh <<<<  asdf -WarningVariable warn -WarningAction stop

    + CategoryInfo          : OperationStopped: (:) [Invoke-NaSsh], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : ActionPreferenceStop,DataONTAP.PowerShell.SDK.Cmdlets.Toolkit.Ssh.InvokeNaSsh


Hi Clinton,

Do we have any kind of fsecurity equivalent cmdlet on the roadmap?  It would be nice to be able to set permissions on qtrees and folders via a cmdlet in a similar manner to Set-NaCifsShareAcl.



NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner