Microsoft Virtualization Discussions
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?
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
Join our Discord Community