PowerShell – Determine Domain and Do Something

email me

This can be used to determine a domain, in a multi-domain enterprise. If a specific domain, do something.

$a = (Get-WmiObject Win32_ComputerSystem).Domain

switch ($a) 
    { 
        "domain1.com" {"Domain1.com"} 
        "domain2.com" {"Domain2.com"} 
        "WORKGROUP" {"Workgroup"} 
        
        default {"Everyone Else"}
    }