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   [ - ] Hide Comments


Please log in to comment

Community Chosen Answer



$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.

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.

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'"

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

Answered 09/03/2016 by: rileyz
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity


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

Answered 09/03/2016 by: flip1001
Third Degree Brown Belt

  • You can do it for free (:
    See my comment above.
    • Thanks for the updated script.
  • 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.
Please log in to comment

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!

Answered 09/03/2016 by: MichAda
Orange Belt

Please log in to comment

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"

Answered 09/06/2016 by: MichAda
Orange Belt

Please log in to comment