Tag Archives: scripting

PowerShell and DNS

Here is a quick one liner to show how you can pull DNS information and filter it using powershell.  Replace zonename with the name of the zone you want to pull information from and replace computername with the name of the computer you are searching for.

dnscmd.exe /zoneprint zonename | where{$_ -like "*computername*"}


Delete User Profile

The other day I was in need of deleting over 100 profiles and found the built-in Windows tool to be inefficient for this task.  I came across some PowerShell code that was a life saver.  Using the code below I was able to write a script and automate the task.

Finding the User Profile:

$username = "user"

$computername = “computer”

$userProfile = Get-WmiObject -computer $computername win32_userprofile -filter “LocalPath like `’%\\$username`'”

Note: Edit $computername variable with the name of the computer with the profile on it.  Yes this can be done remotely.  Also edit the $username variable with the user you are looking for.

Verify Correct User Profile:


Note: You do not want to delete the wrong user profile.  Always double check.

Deleting the User Profile:

$userProfile | Remove-WmiObject

Note: This code is only for users that have been properly logged off and their registry hive has been unloaded.  If you see an error, one of those two reasons may be the problem.   Restarting before you delete is one way to make sure the registry hive is unloaded.