2012-08-09 03:47 PM
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?
2012-08-09 04:30 PM
That's pretty straightforward:
if (!(Get-NaUser eric -ErrorAction SilentlyContinue))
New-NaUser eric -group users -password toolkit1!
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