Chapter 27. Enterprise Computer Management

Introduction

When working with Windows systems across an enterprise, this question often arises: “How do I do <some task> in PowerShell?” In an administrator’s perfect world, anybody who designs a feature with management implications also supports (via PowerShell cmdlets) the tasks that manage that feature. Many management tasks have been around longer than PowerShell, though, so the answer can sometimes be, “The same way you did it before PowerShell.”

That’s not to say that your life as an administrator doesn’t improve with the introduction of PowerShell, however. Pre-PowerShell administration tasks generally fall into one of several models: command-line utilities, Windows Management Instrumentation (WMI) interaction, registry manipulation, file manipulation, interaction with COM objects, or interaction with .NET objects.

PowerShell makes it easier to interact with all these task models, and therefore makes it easier to manage functionality that depends on them.

Join a Computer to a Domain or Workgroup

Problem

You want to join a computer to a domain or workgroup.

Solution

Use the -DomainName parameter of the Add-Computer cmdlet to add a computer to a domain. Use the -WorkGroupName parameter to add it to a workgroup.

PS > Add-Computer -DomainName MyDomain -Credential MyDomain\MyUser
PS > Restart-Computer

Discussion

The Add-Computer cmdlet’s name is fairly self-descriptive: it lets you add a computer to a domain or workgroup. Since a domain join only ...

Get Windows PowerShell Cookbook, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.