O'Reilly logo

Windows PowerShell Cookbook, 3rd Edition by Lee Holmes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required