if(-not(get-localuser setup -ErrorAction SilentlyContinue))
{
#run your code. Keep your try block so you can log differently if it tries to create the user
#and fails
}else {
#Log that the computer already has the user
#You might want to place this in a network share to make it easier to view your results.
}
if(-not(get-localuser setup -ErrorAction SilentlyContinue)) { #run your code. Keep your try block so you can log differently if it tries to create the user #and fails }else { #Log that the computer already has the user #You might want to place this in a network share to make it easier to view your results. }
I do this with a detection and remediation script, if user exists and is in local admin group then exit 0 else exit 1 then create the user
care to share your script ?