Managing Domain Memberships with PowerShell

Let’s go through some steps that may prove helpful in speeding up your processes in joining machines to a domain, or helping you to migrate machines to a new domain at scale. We will utilize some pretty simple PowerShell to accomplish this task. So without further ado, grab a drink, sit back, and let’s do this!

Checking Domain Membership

We need some logic to see if the machine is currently a member of a domain. That’s pretty simple with PowerShell. The code looks like this (and will return a true/false value):

(Get-WMIObject win32_computersystem).partofdomain

Removing a Machine from a Domain

This also is going to return to us a true/false value. Given that we want to put the machine on a new domain, let’s use some logic to automate removing the machine from its current domain membership.

If ( (Get-WMIObject win32_computersystem).partofdomain 

2 responses

  • Minor typo, Get-WMIObject in the beginning of the article is correct but in the other 2 instances, the dash is in the wrong spot. Also the script failed on me until I moved the function before the if/else statement. Other than that I’m still new to powershell and I enjoy reading these posts.

Your email address will not be published.

Your Name

This site uses Akismet to reduce spam. Learn how your comment data is processed.