Introduction to Windows PowerShell

1 2 3 4 5 6 7 8 9 10 11 12 Page 11
Page 11 of 12

The default provider drives on Windows 7 are listed in Table 1.

Table 1  Provider Drives on Windows 7

Drive Name

Contains

A:, B:, C:, and so on

Disk drives (FileSystem provider)

Alias:

List of PowerShell aliases

Cert:

Digital certificates

Env:

Environment variables

Function:

Defined functions

HKCU:

Registry section HKEY_CURRENT_USER

HKLM:

Registry section HKEY_LOCAL_MACHINE

Variable:

PowerShell variables

WSMan:

Windows Services Management connections to the local and remote computers

Name completion works with these drives, too. For example, if you type dir hklm:soft and press the Tab key, PowerShell changes soft to SOFTWARE, which is the first Registry key that matches the partial name you typed. You can continue the path by typing \ and another part of a key name.

Try typing these commands at the PowerShell prompt (and notice that you don’t have to capitalize them; the names are case insensitive):

dir hklm:\software

This lists the keys under HKEY_LOCAL_MACHINE\SOFTWARE.

cd hklm:\software

Makes the Registry your “current location.”

dir

Lists the keys in this current location.

cd $home

Returns to the file system in your profile folder.

dir cert:\currentuser

Lists certificates associated with your use account.

dir variable:

Lists all variables currently defined in Windows PowerShell.

dir env:

This lists all defined environment variables.

Many PowerShell cmdlets can work with objects specified by their paths whether the paths point to a file, a Registry key, a certificate, or whatever. For example, the del command (which is an alias for delete-item) can delete a Registry key just as easily as a file, with a command like del hkcu:\software\badkey.

PowerShell Security

Because Windows PowerShell can be used to change Windows settings and has the potential, if run by a privileged user, of undermining Windows’ security system, Microsoft has taken care to be sure that it’s difficult to run PowerShell scripts without your taking intentional steps to enable them. There are additional barriers to running scripts that come from the Internet, via email, Instant Messaging programs, and so on. This was done to avert the possibility that hackers might figure out ways to exploit potential flaws in, say Internet Explorer, to install and run PowerShell scripts on your system without your permission.

PowerShell Scripts and User Account Control

Windows PowerShell was designed first and foremost for managing Windows, so you will end up wanting it to do things that require Administrator privileges. On Windows 7 and Vista, PowerShell, requires elevated privileges—just running it from a Computer Administrator account isn’t enough. Either open an elevated command prompt and then type powershell or use any of the methods you’d use to run cmd.exe with elevated privileges, but run powershell.exe instead.

On Windows XP, to perform administrative functions, you’ll have to be logged in as a Computer Administrator when you start PowerShell. Alternatively, you can use the runas command to start powershell.exe in the context of an Administrator’s user account.

Whatever version of Windows you’re using, you’ll probably want to try this right away, as you want to use a privileged PowerShell command to let you run PowerShell script files. I describe this command next.

1 2 3 4 5 6 7 8 9 10 11 12 Page 11
Page 11 of 12
7 inconvenient truths about the hybrid work trend
Shop Tech Products at Amazon