Microsoft Virtualization Discussions

how to error check existing user

stephen2

Trying to write a script to add local groups, roles, users to multiple filers.

When invoking new-nauser, the script terminates if the user already exists. Is there a way to check if the user exists prior to executing new-nauser?

What would the syntax be for using Get-NaUser to check if the user already exists without the script bombing out?

1 REPLY 1

timothyn

That's pretty straightforward:

if (!(Get-NaUser eric -ErrorAction SilentlyContinue))

{

    New-NaUser eric -group users -password toolkit1!

}

else

{

    Write-Warning "User eric already exists"

}

or if you are confident your command won't fail for other reasons (e.g. bad group/password):

New-NaUser eric -group users -password toolkit1! -ErrorAction SilentlyContinue

Announcements
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
Public