Computer identity and domain membership management in PowerShell are handled through dedicated system administration cmdlets. The Get-ComputerInfo, Rename-Computer, Add-Computer, and Remove-Computer cmdlets automate tasks such as retrieving hardware and operating system inventory, enforcing standard naming conventions, and managing Active Directory domain enrollment. These cmdlets replace manual GUI operations and legacy utilities like systeminfo.exe.
Querying System Inventory with Get-ComputerInfo
The Get-ComputerInfo cmdlet consolidates information from dozens of underlying CIM/WMI classes into a single, comprehensive Microsoft.PowerShell.Commands.ComputerInfo object. It acts as the modern, structured replacement for the legacy systeminfo.exe tool, returning a comprehensive snapshot of hardware, OS, and network identity details for the local machine.
Get-ComputerInfoWindowsBuildLabEx : 19041.1.amd64fre.vb_release.191206-1406
WindowsCurrentVersion : 6.3
WindowsEditionId : Professional
WindowsInstallationType : Client
WindowsInstallDateFromRegistry : 3/19/2026 6:51:57 PM
WindowsProductId : 00330-80000-00000-AA559
WindowsProductName : Windows 10 Pro
...Filtering Specific Properties
Get-ComputerInfo -Property "CsName", "CsDomain", "WindowsProductName"where -Property one or more property names (supports wildcards) to limit the returned output.
CsName CsDomain WindowsProductName
------ -------- ------------------
DESKTOP-N7 WORKGROUP Windows 10 ProBuilding a Custom Inventory Report
Get-ComputerInfo -Property CsName, WindowsProductName, WindowsVersion, OsTotalPhysicalMemory, CsDomain |
Select-Object -Property CsName,
WindowsProductName,
WindowsVersion,
@{Name="RAM(GB)"; Expression={[math]::Round($_.OsTotalPhysicalMemory / 1GB, 2)}},
CsDomainwhere:
Get-ComputerInfois the cmdlet for querying operating system and computer hardware metrics.-Propertyrestricts data retrieval to specified properties. Limiting properties significantly reduces command execution time.CsNameis the configured NetBIOS/computer name.WindowsProductNameis the operating system release edition (e.g., Windows 11 Enterprise).WindowsVersionis the operating system build release identification.OsTotalPhysicalMemoryis total installed RAM measured in bytes.- The
CsDomainfield represents the domain or workgroup that the computer is part of.
./get-computer-inventory.ps1CsName : DESKTOP-N7
WindowsProductName : Windows 10 Pro
WindowsVersion : 2009
RAM(GB) : 0
CsDomain : WORKGROUPRenaming a Computer with Rename-Computer
The Rename-Computer cmdlet changes the computer name in the local registry and updates the active Active Directory computer object if the machine is domain-joined.
Rename-Computer -NewName "WKSTN-042" -Restartwhere:
-NewNameis the new hostname to assign to the computer (limited to 15 alphanumeric characters for NetBIOS compatibility).-Restartautomatically restarts the computer to apply the change.
Confirming the Result with -PassThru
Rename-Computer -NewName "WS-FIN-042" -Force -PassThruwhere:
Rename-Computeris the cmdlet that modifies the local computer identity.-NewNamespecifies the new NetBIOS name.-Forcesuppresses interactive confirmation prompts.-PassThrureturns aRenameComputerQueryResultobject showing the outcome; by default, this cmdlet returns no output.
./rename-computer-demo.ps1HasSucceeded OldComputerName NewComputerName
------------ --------------- ---------------
True WS-FIN-01 WS-FIN-042Renaming a Remote Computer
Rename-Computer -ComputerName "OLD-PC01" -NewName "WKSTN-043" -DomainCredential (Get-Credential) -Restartwhere:
-ComputerNameis the current name (or address) of the remote computer to rename.-DomainCredentialare credentials with permission to rename a domain-joined computer.
Joining a Domain with Add-Computer
The Add-Computer cmdlet joins the local machine to an Active Directory domain or a workgroup, replacing manual GUI enrollment via System Properties. It also optionally assigns the computer to a target Organizational Unit (OU).
Add-Computer -DomainName "corp.contoso.com" -Credential (Get-Credential) -Restartwhere:
-DomainNameis the fully qualified domain name (FQDN) to join.-Credentialis an account with permission to join computers to the domain.-Restartrestarts the computer immediately after joining, which is required to complete the process.
Specifying an Organizational Unit (OU)
$cred = Get-Credential -UserName "CORP\admin_join" -Message "Enter Domain Join Credentials"
Add-Computer -DomainName "corp.internal" `
-OUPath "OU=Finance,OU=Workstations,DC=corp,DC=internal" `
-Credential $cred `
-PassThruwhere:
Add-Computeris the cmdlet managing domain and workgroup enrollment.-DomainNameis the fully qualified domain name (FQDN) of the target Active Directory domain.-OUPathis the LDAP distinguished name of the Organizational Unit where the computer account will be created.-Credentialis aPSCredentialobject holding authorized domain join credentials.-PassThruemits an object summarizing the success of the join operation.
./join-domain.ps1HasSucceeded Domain ComputerName
------------ ------ ------------
True corp.internal WS-FIN-042Leaving a Domain with Remove-Computer
The Remove-Computer cmdlet removes the local machine from its current domain, returning it to a workgroup. It can unjoin either the local or a remote machine.
Remove-Computer -UnjoinDomainCredential (Get-Credential) -WorkgroupName "WORKGROUP" -Restartwhere:
-UnjoinDomainCredentialare domain credentials authorized to remove the computer from the domain.-WorkgroupNameis the workgroup name to assign after leaving the domain (standard default isWORKGROUP).-Restartrestarts the computer to complete the unjoin process.
Confirming the Result with -PassThru
$cred = Get-Credential -UserName "CORP\admin_join" -Message "Enter Domain Removal Credentials"
Remove-Computer -WorkgroupName "WORKGROUP" -Credential $cred -Force -PassThruwhere:
Remove-Computerdisjoins the computer from its current domain.-WorkgroupNamespecifies the target standalone workgroup name.-Credentialare domain credentials authorized to remove the computer object from Active Directory.-Forcesuppresses interactive prompts.
./unjoin-domain.ps1HasSucceeded ComputerName
------------ ------------
True WS-FIN-042Practical Usage: Automated Workstation Provisioning
During new machine deployments, administrators typically enforce naming conventions based on asset tags and join the computer to the domain in a single automated step. A common deployment task is renaming a freshly imaged machine and joining it to the corporate domain in one unattended sequence.
param(
[Parameter(Mandatory = $true)]
[string]$AssetTag,
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]$Credential,
[string]$DomainName = "corp.internal",
[string]$OUPath = "OU=Workstations,DC=corp,DC=internal"
)
$targetHostName = "WS-$AssetTag"
$currentHostName = $env:COMPUTERNAME
Write-Output "Starting provisioning sequence for $targetHostName..."
if ($currentHostName -ne $targetHostName) {
Write-Output "Renaming host from $currentHostName to $targetHostName..."
Rename-Computer -NewName $targetHostName -Force
}
Write-Output "Enrolling $targetHostName into $DomainName..."
Add-Computer -DomainName $DomainName `
-OUPath $OUPath `
-Credential $Credential `
-Restart `
-Forcewhere:
param (...)accepts input parameters including the unique asset tag and the administrative domain credential.$env:COMPUTERNAMEis the automatic environment variable storing the active system hostname.if ($currentHostName -ne $targetHostName)is a conditional check to avoid unnecessary renaming steps if the target name is already applied.Rename-Computer -Forceapplies the rename without an additional confirmation prompt.Add-Computer -Forcesuppresses confirmation prompts during the join, restarting automatically once complete.-Restartautomatically initiates a reboot after the domain join operation succeeds.
$cred = Get-Credential
./provision-workstation.ps1 -AssetTag "4892" -Credential $credStarting provisioning sequence for WS-4892...
Renaming host from DESKTOP-XJ84 to WS-4892...
Enrolling WS-4892 into corp.internal...