Skip to content

PowerShell Computer Management

How to manage computer identity, domain membership, and system inventory in PowerShell using cmdlets like Get-ComputerInfo, Rename-Computer, Add-Computer, and Remove-Computer for automation and Active Directory integration.

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.

Consolepowershell
Get-ComputerInfo
Outputplaintext
WindowsBuildLabEx                                       : 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

Consolepowershell
Get-ComputerInfo -Property "CsName", "CsDomain", "WindowsProductName"

where -Property one or more property names (supports wildcards) to limit the returned output.

Outputplaintext
CsName     CsDomain  WindowsProductName
------     --------  ------------------
DESKTOP-N7 WORKGROUP Windows 10 Pro

Building a Custom Inventory Report

get-computer-inventory.ps1powershell
Get-ComputerInfo -Property CsName, WindowsProductName, WindowsVersion, OsTotalPhysicalMemory, CsDomain | 
    Select-Object -Property CsName, 
        WindowsProductName, 
        WindowsVersion, 
        @{Name="RAM(GB)"; Expression={[math]::Round($_.OsTotalPhysicalMemory / 1GB, 2)}}, 
        CsDomain

where:

  • Get-ComputerInfo is the cmdlet for querying operating system and computer hardware metrics.
  • -Property restricts data retrieval to specified properties. Limiting properties significantly reduces command execution time.
  • CsName is the configured NetBIOS/computer name.
  • WindowsProductName is the operating system release edition (e.g., Windows 11 Enterprise).
  • WindowsVersion is the operating system build release identification.
  • OsTotalPhysicalMemory is total installed RAM measured in bytes.
  • The CsDomain field represents the domain or workgroup that the computer is part of.
Consolepowershell
./get-computer-inventory.ps1
Outputplaintext
CsName             : DESKTOP-N7
WindowsProductName : Windows 10 Pro
WindowsVersion     : 2009
RAM(GB)            : 0
CsDomain           : WORKGROUP

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

Consolepowershell
Rename-Computer -NewName "WKSTN-042" -Restart

where:

  • -NewName is the new hostname to assign to the computer (limited to 15 alphanumeric characters for NetBIOS compatibility).
  • -Restart automatically restarts the computer to apply the change.

Confirming the Result with -PassThru

rename-computer-demo.ps1powershell
Rename-Computer -NewName "WS-FIN-042" -Force -PassThru

where:

  • Rename-Computer is the cmdlet that modifies the local computer identity.
  • -NewName specifies the new NetBIOS name.
  • -Force suppresses interactive confirmation prompts.
  • -PassThru returns a RenameComputerQueryResult object showing the outcome; by default, this cmdlet returns no output.
Consolepowershell
./rename-computer-demo.ps1
Outputplaintext
HasSucceeded OldComputerName NewComputerName
------------ --------------- ---------------
True         WS-FIN-01       WS-FIN-042

Renaming a Remote Computer

Consolepowershell
Rename-Computer -ComputerName "OLD-PC01" -NewName "WKSTN-043" -DomainCredential (Get-Credential) -Restart

where:

  • -ComputerName is the current name (or address) of the remote computer to rename.
  • -DomainCredential are 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).

Consolepowershell
Add-Computer -DomainName "corp.contoso.com" -Credential (Get-Credential) -Restart

where:

  • -DomainName is the fully qualified domain name (FQDN) to join.
  • -Credential is an account with permission to join computers to the domain.
  • -Restart restarts the computer immediately after joining, which is required to complete the process.

Specifying an Organizational Unit (OU)

join-domain.ps1powershell
$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 `
    -PassThru

where:

  • Add-Computer is the cmdlet managing domain and workgroup enrollment.
  • -DomainName is the fully qualified domain name (FQDN) of the target Active Directory domain.
  • -OUPath is the LDAP distinguished name of the Organizational Unit where the computer account will be created.
  • -Credential is a PSCredential object holding authorized domain join credentials.
  • -PassThru emits an object summarizing the success of the join operation.
Consolepowershell
./join-domain.ps1
Outputplaintext
HasSucceeded Domain        ComputerName
------------ ------        ------------
True         corp.internal WS-FIN-042

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

Consolepowershell
Remove-Computer -UnjoinDomainCredential (Get-Credential) -WorkgroupName "WORKGROUP" -Restart

where:

  • -UnjoinDomainCredential are domain credentials authorized to remove the computer from the domain.
  • -WorkgroupName is the workgroup name to assign after leaving the domain (standard default is WORKGROUP).
  • -Restart restarts the computer to complete the unjoin process.

Confirming the Result with -PassThru

unjoin-domain.ps1powershell
$cred = Get-Credential -UserName "CORP\admin_join" -Message "Enter Domain Removal Credentials"

Remove-Computer -WorkgroupName "WORKGROUP" -Credential $cred -Force -PassThru

where:

  • Remove-Computer disjoins the computer from its current domain.
  • -WorkgroupName specifies the target standalone workgroup name.
  • -Credential are domain credentials authorized to remove the computer object from Active Directory.
  • -Force suppresses interactive prompts.
Consolepowershell
./unjoin-domain.ps1
Outputplaintext
HasSucceeded ComputerName
------------ ------------
True         WS-FIN-042

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

provision-workstation.ps1powershell
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 `
    -Force

where:

  • param (...) accepts input parameters including the unique asset tag and the administrative domain credential.
  • $env:COMPUTERNAME is 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 -Force applies the rename without an additional confirmation prompt.
  • Add-Computer -Force suppresses confirmation prompts during the join, restarting automatically once complete.
  • -Restart automatically initiates a reboot after the domain join operation succeeds.
Consolepowershell
$cred = Get-Credential
./provision-workstation.ps1 -AssetTag "4892" -Credential $cred
Outputplaintext
Starting provisioning sequence for WS-4892...
Renaming host from DESKTOP-XJ84 to WS-4892...
Enrolling WS-4892 into corp.internal...
Navigation