/build/static/layout/Breadcrumb_cap_w.png

Identify and remove local account

We have a windows 7 scripted image that creates a user called SciptedUser.  We often forget to remove that account before moving the system to production.

Anybody know of an easy way to use the K1000 to locate systems with that account, and then have it remove the account?


0 Comments   [ + ] Show comments

Answers (4)

Posted by: rileyz 8 years ago
Red Belt
2
*cough...

$DebugPreference = 'Continue' #Continue|SilentlyContinue$LocalAccountsArray = Get-WmiObject -Class Win32_UserAccount -Filter  "LocalAccount='True'" |   Select Name#https://mcpmag.com/articles/2015/04/15/reporting-on-local-accounts.aspx$RemoveThisUser = 'SciptedUser'Foreach ($User in $LocalAccountsArray)    {$User = ($user.name) #Convert psobject to string     Write-debug "Working on $User"     If ($User -eq "$RemoveThisUser")             {Write-Warning "Removing account $User"             &net User `"$user`" /Delete}}

Blah its all jibberish, try here - url expires on 30/09/16.
http://pastebin.com/Z1bW1jrA

You'll need to run this via PowerShell on the systems. If you are copying and pasting, make sure your double and singles are proper ones! Not the angled ones. Sometimes when its published online they mangle the quotes.


*Addition 
If you want to remove the profile then add code block below before the &net User `"$user`" /Delete line. Edit in PowerShell ISE as it will let you know if the syntax is wrong.

$UserProfile = Get-WmiObject Win32_UserProfile -filter "localpath='C:\\Users\\$User'"
$UserProfile.Delete()

*Updated
I rewrote it, please see the URL below. Instead of using the foreach loop I decided it would be better to use the contains method - more efficient than processing every record in the array. Anyway here it is..

ps. not my fault if it blows up your computer :D

Posted by: flip1001 8 years ago
Black Belt
1
There are 2 steps required: Remove the user profile and delete the user account.

Delprof2 – User Profile Deletion Tool can be used for the first part, but you may have to pay for it. Look at its website for details.

Here is a batch file you can use with delprof2 attached to an offline Kscript.

IF EXIST "C:\USERS\SciptedUser\." (
REM Delete profile for ScriptedUser
delprof2.exe /u /id:SciptedUser
REM Delete the account on the local machine
NET USER SciptedUser /DELETE
)


Comments:
  • You can do it for free (:
    See my comment above. - rileyz 8 years ago
    • Thanks for the updated script. - flip1001 8 years ago
  • flip1001,

    Thanks for the input! I was able to use your batch file recommendation as a test, and it worked great! But they want too much for 'delprof2' and I'm sure my manager will not fund it. Super easy solution though. - MichAda 8 years ago
Posted by: MichAda 8 years ago
Orange Belt
0

Nice...I'll give it try when I return Tuesday.

Thanks for posting the url.  I was able to copy the raw paste data.

Have a great long weekend!

Posted by: MichAda 8 years ago
Orange Belt
0

How should I set up the power shell script on KACE?

I used method 2 from knowledge base 138389 but keep getting an error:

Missing expression after unary operator '-'.At line:1 char:2

The command I'm using in "Parameters" is:

-nologo -executionpolicy bypass -noprofile -file "FileName.ps1"

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ