diff --git a/reference/docs-conceptual/samples/Changing-Computer-State.md b/reference/docs-conceptual/samples/Changing-Computer-State.md index 753aa6f0c62e..3a0eaed3eb97 100644 --- a/reference/docs-conceptual/samples/Changing-Computer-State.md +++ b/reference/docs-conceptual/samples/Changing-Computer-State.md @@ -8,7 +8,7 @@ ms.assetid: 8093268b-27f8-4a49-8871-142c5cc33f01 To reset a computer in Windows PowerShell, use either a standard command-line tool or a WMI class. Although you are using Windows PowerShell only to run the tool, learning how to change a computer's power state in Windows PowerShell illustrates some of the important details about working with external tools in Windows PowerShell. -### Locking a Computer +## Locking a Computer The only way to lock a computer directly with the standard available tools is to call the **LockWorkstation()** function in **user32.dll**: @@ -22,7 +22,7 @@ When you lock a workstation while Fast User Switching is enabled, such as on Win To shut down particular sessions on a Terminal Server, use the **tsshutdn.exe** command-line tool. -### Logging Off the Current Session +## Logging Off the Current Session You can use several different techniques to log off of a session on the local system. The simplest way is to use the Remote Desktop/Terminal Services command-line tool, **logoff.exe** (For details, at the Windows PowerShell prompt, type **logoff /?**). To log off the current active session, type **logoff** with no arguments. @@ -40,7 +40,7 @@ A third option is to use WMI. The Win32_OperatingSystem class has a Win32Shutdow For more information, and to find other features of the Win32Shutdown method, see "Win32Shutdown Method of the Win32_OperatingSystem Class" in MSDN. -### Shutting Down or Restarting a Computer +## Shutting Down or Restarting a Computer Shutting down and restarting computers are generally the same types of task. Tools that shut down a computer will generally restart it as well—and vice versa. There are two straightforward options for restarting a computer from Windows PowerShell. Use either Tsshutdn.exe or Shutdown.exe with appropriate arguments. You can get detailed usage information from **tsshutdn.exe /?** or **shutdown.exe /?**. diff --git a/reference/docs-conceptual/samples/Collecting-Information-About-Computers.md b/reference/docs-conceptual/samples/Collecting-Information-About-Computers.md index ac828b4acbd7..fa5dcb3070f2 100644 --- a/reference/docs-conceptual/samples/Collecting-Information-About-Computers.md +++ b/reference/docs-conceptual/samples/Collecting-Information-About-Computers.md @@ -16,7 +16,7 @@ We specify the **ComputerName** parameter with the dot value (**.**), which repr You can specify a name or IP address associated with any computer you can reach through WMI. To retrieve information about the local computer, you could omit the **ComputerName** parameter. -### Listing Desktop Settings +## Listing Desktop Settings We'll begin with a command that collects information about the desktops on the local computer. @@ -38,7 +38,7 @@ Get-CimInstance -ClassName Win32_Desktop -ComputerName . | Select-Object -Exclud To filter out the metadata, use a pipeline operator (|) to send the results of the `Get-CimInstance` command to `Select-Object -ExcludeProperty "CIM*"`. -### Listing BIOS Information +## Listing BIOS Information The WMI **Win32_BIOS** class returns fairly compact and complete information about the system BIOS on the local computer: @@ -46,7 +46,7 @@ The WMI **Win32_BIOS** class returns fairly compact and complete information abo Get-CimInstance -ClassName Win32_BIOS -ComputerName . ``` -### Listing Processor Information +## Listing Processor Information You can retrieve general processor information by using WMI's **Win32_Processor** class, although you will likely want to filter the information: @@ -64,7 +64,7 @@ SystemType X86-based PC ``` -### Listing Computer Manufacturer and Model +## Listing Computer Manufacturer and Model Computer model information is also available from **Win32_ComputerSystem**. The standard displayed output will not need any filtering to provide OEM data: @@ -82,7 +82,7 @@ MyPC Jane Doe WORKGROUP 804765696 DA243A-ABA 6415cl NA910 Comp Your output from commands such as this, which return information directly from some hardware, is only as good as the data you have. Some information is not correctly configured by hardware manufacturers and may therefore be unavailable. -### Listing Installed Hotfixes +## Listing Installed Hotfixes You can list all installed hotfixes by using **Win32_QuickFixEngineering**: @@ -137,7 +137,7 @@ HotFixId KB4048951 ``` -### Listing Operating System Version Information +## Listing Operating System Version Information The **Win32_OperatingSystem** class properties include version and service pack information. You can explicitly select only these properties to get a version information summary from **Win32_OperatingSystem**: @@ -161,7 +161,7 @@ ServicePackMajorVersion : 0 ServicePackMinorVersion : 0 ``` -### Listing Local Users and Owner +## Listing Local Users and Owner Local general user information — number of licensed users, current number of users, and owner name — can be found with a selection of **Win32_OperatingSystem** class' properties. You can explicitly select the properties to display like this: @@ -176,7 +176,7 @@ A more succinct version using wildcards is: Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName . | Select-Object -Property *user* ``` -### Getting Available Disk Space +## Getting Available Disk Space To see the disk space and free space for local drives, you can use the Win32_LogicalDisk WMI class. You need to see only instances with a DriveType of 3 — the value WMI uses for fixed hard disks. @@ -197,7 +197,7 @@ FreeSpace 109839607808 Size 326846914560 ``` -### Getting Logon Session Information +## Getting Logon Session Information You can get general information about logon sessions associated with users through the **Win32_LogonSession** WMI class: @@ -205,7 +205,7 @@ You can get general information about logon sessions associated with users throu Get-CimInstance -ClassName Win32_LogonSession -ComputerName . ``` -### Getting the User Logged on to a Computer +## Getting the User Logged on to a Computer You can display the user logged on to a particular computer system using Win32_ComputerSystem. This command returns only the user logged on to the system desktop: @@ -214,7 +214,7 @@ This command returns only the user logged on to the system desktop: Get-CimInstance -ClassName Win32_ComputerSystem -Property UserName -ComputerName . ``` -### Getting Local Time from a Computer +## Getting Local Time from a Computer You can retrieve the current local time on a specific computer by using the **Win32_LocalTime** WMI class. @@ -234,7 +234,7 @@ Year : 2017 PSComputerName : . ``` -### Displaying Service Status +## Displaying Service Status To view the status of all services on a specific computer, you can locally use the `Get-Service` cmdlet. For remote systems, you can use the **Win32_Service** WMI class. diff --git a/reference/docs-conceptual/samples/Creating-.NET-and-COM-Objects--New-Object-.md b/reference/docs-conceptual/samples/Creating-.NET-and-COM-Objects--New-Object-.md index 9e9ad4f15d02..a0d77d5162ba 100644 --- a/reference/docs-conceptual/samples/Creating-.NET-and-COM-Objects--New-Object-.md +++ b/reference/docs-conceptual/samples/Creating-.NET-and-COM-Objects--New-Object-.md @@ -8,7 +8,7 @@ ms.assetid: 2057b113-efeb-465e-8b44-da2f20dbf603 There are software components with .NET Framework and COM interfaces that enable you to perform many system administration tasks. Windows PowerShell lets you use these components, so you are not limited to the tasks that can be performed by using cmdlets. Many of the cmdlets in the initial release of Windows PowerShell do not work against remote computers. We will demonstrate how to get around this limitation when managing event logs by using the .NET Framework **System.Diagnostics.EventLog** class directly from Windows PowerShell. -### Using New-Object for Event Log Access +## Using New-Object for Event Log Access The .NET Framework Class Library includes a class named **System.Diagnostics.EventLog** that can be used to manage event logs. You can create a new instance of a .NET Framework class by using the **New-Object** cmdlet with the **TypeName** parameter. For example, the following command creates an event log reference: @@ -21,7 +21,7 @@ PS> New-Object -TypeName System.Diagnostics.EventLog Although the command has created an instance of the EventLog class, the instance does not include any data. That is because we did not specify a particular event log. How do you get a real event log? -#### Using Constructors with New-Object +### Using Constructors with New-Object To refer to a specific event log, you need to specify the name of the log. **New-Object** has an **ArgumentList** parameter. The arguments you pass as values to this parameter are used by a special startup method of the object. The method is called a *constructor* because it is used to construct the object. For example, to get a reference to the Application log, you specify the string 'Application' as an argument: @@ -36,7 +36,7 @@ Max(K) Retain OverflowAction Entries Name > [!NOTE] > Since most of the .NET Framework core classes are contained in the System namespace, Windows PowerShell will automatically attempt to find classes you specify in the System namespace if it cannot find a match for the typename you specify. This means that you can specify Diagnostics.EventLog instead of System.Diagnostics.EventLog. -#### Storing Objects in Variables +### Storing Objects in Variables You might want to store a reference to an object, so you can use it in the current shell. Although Windows PowerShell lets you do a lot of work with pipelines, lessening the need for variables, sometimes storing references to objects in variables makes it more convenient to manipulate those objects. @@ -56,7 +56,7 @@ PS> $AppLog 16,384 7 OverwriteOlder 2,160 Application ``` -#### Accessing a Remote Event Log with New-Object +### Accessing a Remote Event Log with New-Object The commands used in the preceding section target the local computer; the **Get-EventLog** cmdlet can do that. To access the Application log on a remote computer, you must supply both the log name and a computer name (or IP address) as arguments. @@ -71,7 +71,7 @@ PS> $RemoteAppLog Now that we have a reference to an event log stored in the $RemoteAppLog variable, what tasks can we perform on it? -#### Clearing an Event Log with Object Methods +### Clearing an Event Log with Object Methods Objects often have methods that can be called to perform tasks. You can use **Get-Member** to display the methods associated with an object. The following command and selected output show some the methods of the EventLog class: @@ -112,7 +112,7 @@ PS> $RemoteAppLog 512 7 OverwriteOlder 0 Application ``` -### Creating COM Objects with New-Object +## Creating COM Objects with New-Object You can use **New-Object** to work with Component Object Model (COM) components. Components range from the various libraries included with Windows Script Host (WSH) to ActiveX applications such as Internet Explorer that are installed on most systems. **New-Object** uses .NET Framework Runtime-Callable Wrappers to create COM objects, so it has the same limitations that .NET Framework does when calling COM objects. To create a COM object, you need to specify the **ComObject** parameter with the Programmatic Identifier or *ProgId* of the COM class you want to use. A complete discussion of the limitations of COM use and determining what ProgIds are available on a system is beyond the scope of this user's guide, but most well-known objects from environments such as WSH can be used within Windows PowerShell. @@ -128,7 +128,7 @@ New-Object -ComObject Scripting.FileSystemObject Although most of the functionality of these classes is made available in other ways in Windows PowerShell, a few tasks such as shortcut creation are still easier to do using the WSH classes. -### Creating a Desktop Shortcut with WScript.Shell +## Creating a Desktop Shortcut with WScript.Shell One task that can be performed quickly with a COM object is creating a shortcut. Suppose you want to create a shortcut on your desktop that links to the home folder for Windows PowerShell. You first need to create a reference to **WScript.Shell**, which we will store in a variable named **$WshShell**: @@ -197,7 +197,7 @@ $lnk.TargetPath = $PSHome $lnk.Save() ``` -### Using Internet Explorer from Windows PowerShell +## Using Internet Explorer from Windows PowerShell Many applications (including the Microsoft Office family of applications and Internet Explorer) can be automated by using COM. Internet Explorer illustrates some of the typical techniques and issues involved in working with COM-based applications. @@ -256,7 +256,7 @@ Remove-Variable ie > [!NOTE] > There is no common standard for whether ActiveX executables exit or continue to run when you remove a reference to one. Depending on circumstances such as whether the application is visible, whether an edited document is running in it, and even whether Windows PowerShell is still running, the application may or may not exit. For this reason, you should test termination behavior for each ActiveX executable you want to use in Windows PowerShell. -### Getting Warnings About .NET Framework-Wrapped COM Objects +## Getting Warnings About .NET Framework-Wrapped COM Objects In some cases, a COM object might have an associated .NET Framework *Runtime-Callable Wrapper* or RCW, and this will be used by **New-Object**. Since the behavior of the RCW may be different from the behavior of the normal COM object, **New-Object** has a **Strict** parameter to warn you about RCW access. If you specify the **Strict** parameter and then create a COM object that uses an RCW, you get a warning message: diff --git a/reference/docs-conceptual/samples/Creating-Get-WinEvent-queries-with-FilterHashtable.md b/reference/docs-conceptual/samples/Creating-Get-WinEvent-queries-with-FilterHashtable.md index b0169447bf66..56caf19c586e 100644 --- a/reference/docs-conceptual/samples/Creating-Get-WinEvent-queries-with-FilterHashtable.md +++ b/reference/docs-conceptual/samples/Creating-Get-WinEvent-queries-with-FilterHashtable.md @@ -31,7 +31,7 @@ Get-WinEvent -FilterHashtable @{ } ``` -### Blog posts about enumeration +## Blog posts about enumeration This article presents information about how to use enumerated values in a hash table. For more information about enumeration, read these **Scripting Guy** blog posts. To create a function that @@ -40,7 +40,7 @@ returns the enumerated values, see For more information, see the [Scripting Guy series of blog posts about enumeration](https://devblogs.microsoft.com/scripting/?s=about+enumeration). -### Hash table key/value pairs +## Hash table key/value pairs To build efficient queries, use the `Get-WinEvent` cmdlet with the **FilterHashtable** parameter. **FilterHashtable** accepts a hash table as a filter to get specific information from Windows event @@ -74,7 +74,7 @@ for a data value. | Data | `` | No | | * | `` | No | -### Building a query with a hash table +## Building a query with a hash table To verify results and troubleshoot problems, it helps to build the hash table one **key/value** pair at a time. The query gets data from the **Application** log. The hash table is equivalent to @@ -109,7 +109,7 @@ If your query needs to get data from archived event logs, use the **Path** key. specifies the full path to the log file. For more information, see the **Scripting Guy** blog post, [Use PowerShell to Parse Saved Event Logs for Errors](https://devblogs.microsoft.com/scripting/use-powershell-to-parse-saved-event-logs-for-errors). -### Using enumerated values in a hash table +## Using enumerated values in a hash table **Keywords** is the next key in the hash table. The **Keywords** data type is an array of the `[long]` value type that holds a large number. Use the following command to find the maximum value of `[long]`: @@ -182,7 +182,7 @@ Get-WinEvent -FilterHashtable @{ } ``` -#### Keywords static property value (optional) +### Keywords static property value (optional) The **Keywords** key is enumerated, but you can use a static property name in the hash table query. Rather than using the returned string, the property name must be converted to a value with the @@ -199,7 +199,7 @@ Get-WinEvent -FilterHashtable @{ } ``` -### Filtering by Event Id +## Filtering by Event Id To get more specific data, the query's results are filtered by **Event Id**. The **Event Id** is referenced in the hash table as the key **ID** and the value is a specific **Event Id**. The @@ -217,7 +217,7 @@ Get-WinEvent -FilterHashtable @{ } ``` -### Filtering by Level +## Filtering by Level To further refine the results and include only events that are errors, use the **Level** key. **Windows Event Viewer** displays the **Level** as string values, but they are enumerated values. In @@ -269,7 +269,7 @@ Get-WinEvent -FilterHashtable @{ } ``` -#### Level static property in enumeration (optional) +### Level static property in enumeration (optional) The **Level** key is enumerated, but you can use a static property name in the hash table query. Rather than using the returned string, the property name must be converted to a value with the diff --git a/reference/docs-conceptual/samples/Managing-Current-Location.md b/reference/docs-conceptual/samples/Managing-Current-Location.md index 61bf79d35532..b5becd81fb36 100644 --- a/reference/docs-conceptual/samples/Managing-Current-Location.md +++ b/reference/docs-conceptual/samples/Managing-Current-Location.md @@ -10,7 +10,7 @@ When navigating folder systems in File Explorer, you usually have a specific wor Windows PowerShell uses the noun **Location** to refer to the working directory, and implements a family of cmdlets to examine and manipulate your location. -### Getting Your Current Location (Get-Location) +## Getting Your Current Location (Get-Location) To determine the path of your current directory location, enter the **Get-Location** command: @@ -24,7 +24,7 @@ C:\Documents and Settings\PowerUser > [!NOTE] > The Get-Location cmdlet is similar to the **pwd** command in the BASH shell. The Set-Location cmdlet is similar to the **cd** command in Cmd.exe. -### Setting Your Current Location (Set-Location) +## Setting Your Current Location (Set-Location) The **Get-Location** command is used with the **Set-Location** command. The **Set-Location** command allows you to specify your current directory location. @@ -90,7 +90,7 @@ chdir -Path .. -PassThru sl -Path HKLM:\SOFTWARE -PassThru ``` -### Saving and Recalling Recent Locations (Push-Location and Pop-Location) +## Saving and Recalling Recent Locations (Push-Location and Pop-Location) When changing locations, it is helpful to keep track of where you have been and to be able to return to your previous location. The **Push-Location** cmdlet in Windows PowerShell creates a ordered history (a "stack") of directory paths where you have been, and you can step back through the history of directory paths by using the complementary **Pop-Location** cmdlet. diff --git a/reference/docs-conceptual/samples/Managing-Windows-PowerShell-Drives.md b/reference/docs-conceptual/samples/Managing-Windows-PowerShell-Drives.md index 16ad863e8ea3..14c6c97ec672 100644 --- a/reference/docs-conceptual/samples/Managing-Windows-PowerShell-Drives.md +++ b/reference/docs-conceptual/samples/Managing-Windows-PowerShell-Drives.md @@ -76,7 +76,7 @@ Path HKLM:\SOFTWARE\Microsoft ``` -### Adding New Windows PowerShell Drives (New-PSDrive) +## Adding New Windows PowerShell Drives (New-PSDrive) You can add your own Windows PowerShell drives by using the **New-PSDrive** command. To get the syntax for the **New-PSDrive** command, enter the **Get-Command** command with the **Syntax** parameter: @@ -140,7 +140,7 @@ cvkey:\ The New-PsDrive cmdlet adds the new drive only to the current Windows PowerShell session. If you close the Windows PowerShell window, the new drive is lost. To save a Windows PowerShell drive, use the Export-Console cmdlet to export the current Windows PowerShell session, and then use the PowerShell.exe **PSConsoleFile** parameter to import it. Or, add the new drive to your Windows PowerShell profile. -### Deleting Windows PowerShell Drives (Remove-PSDrive) +## Deleting Windows PowerShell Drives (Remove-PSDrive) You can delete drives from Windows PowerShell by using the **Remove-PSDrive** cmdlet. The **Remove-PSDrive** cmdlet is easy to use; to delete a specific Windows PowerShell drive, you just supply the Windows PowerShell drive name. @@ -166,6 +166,6 @@ At line:1 char:15 + remove-psdrive <<<< -name office ``` -### Adding and Removing Drives Outside Windows PowerShell +## Adding and Removing Drives Outside Windows PowerShell Windows PowerShell detects file system drives that are added or removed in Windows, including network drives that are mapped, USB drives that are attached, and drives that are deleted by using either the **net use** command or the **WScript.NetworkMapNetworkDrive** and **RemoveNetworkDrive** methods from a Windows Script Host (WSH) script. \ No newline at end of file diff --git a/reference/docs-conceptual/samples/Manipulating-Items-Directly.md b/reference/docs-conceptual/samples/Manipulating-Items-Directly.md index 540308ef4a46..5b67d65d1f44 100644 --- a/reference/docs-conceptual/samples/Manipulating-Items-Directly.md +++ b/reference/docs-conceptual/samples/Manipulating-Items-Directly.md @@ -26,7 +26,7 @@ Cmdlet Rename-Item Rename-Item [-Path] ... Cmdlet Set-Item Set-Item [-Path] ... ``` -### Creating New Items (New-Item) +## Creating New Items (New-Item) To create a new item in the file system, use the **New-Item** cmdlet. Include the **Path** parameter with path to the item, and the **ItemType** parameter with a value of "file" or "directory". @@ -69,7 +69,7 @@ SKC VC Name Property When typing a registry path, be sure to include the colon (**:**) in the Windows PowerShell drive names, HKLM: and HKCU:. Without the colon, Windows PowerShell does not recognize the drive name in the path. -### Why Registry Values are not Items +## Why Registry Values are not Items When you use the **Get-ChildItem** cmdlet to find the items in a registry key, you will never see actual registry entries or their values. @@ -89,7 +89,7 @@ SKC VC Name Property Although it would be convenient to treat registry entries as items, you cannot specify a path to a registry entry in a way that ensures that it is unique. The path notation does not distinguish between the registry subkey named **Run** and the **(Default)** registry entry in the **Run** subkey. Furthermore, because registry entry names can contain the backslash character (**\\**), if registry entries were items, then you could not use the path notation to distinguish a registry entry named **Windows\\CurrentVersion\\Run** from the subkey that is located in that path. -### Renaming Existing Items (Rename-Item) +## Renaming Existing Items (Rename-Item) To change the name of a file or folder, use the **Rename-Item** cmdlet. The following command changes the name of the **file1.txt** file to **fileOne.txt**. @@ -106,7 +106,7 @@ At line:1 char:12 + Rename-Item <<<< -Path C:\temp\New.Directory\fileOne c:\temp\fileOne.txt ``` -### Moving Items (Move-Item) +## Moving Items (Move-Item) To move a file or folder, use the **Move-Item** cmdlet. @@ -122,7 +122,7 @@ Mode LastWriteTime Length Name d---- 2006-05-18 12:14 PM New.Directory ``` -### Copying Items (Copy-Item) +## Copying Items (Copy-Item) If you are familiar with the copy operations in other shells, you might find the behavior of the **Copy-Item** cmdlet in Windows PowerShell to be unusual. When you copy an item from one location to another, Copy-Item does not copy its contents by default. @@ -161,7 +161,7 @@ Mode LastWriteTime Length Name -a--- 2006-05-18 11:44 AM 0 file1 ``` -### Deleting Items (Remove-Item) +## Deleting Items (Remove-Item) To delete files and folders, use the **Remove-Item** cmdlet. Windows PowerShell cmdlets, such as **Remove-Item**, that can make significant, irreversible changes will often prompt for confirmation when you enter its commands. For example, if you try to remove the **New.Directory** folder, you will be prompted to confirm the command, because the folder contains files: @@ -182,7 +182,7 @@ Because **Yes** is the default response, to delete the folder and its files, pre Remove-Item C:\temp\New.Directory -Recurse ``` -### Executing Items (Invoke-Item) +## Executing Items (Invoke-Item) Windows PowerShell uses the **Invoke-Item** cmdlet to perform a default action for a file or folder. This default action is determined by the default application handler in the registry; the effect is the same as if you double-click the item in File Explorer. diff --git a/reference/docs-conceptual/samples/Performing-Networking-Tasks.md b/reference/docs-conceptual/samples/Performing-Networking-Tasks.md index a75a08b107a0..9e59053390fd 100644 --- a/reference/docs-conceptual/samples/Performing-Networking-Tasks.md +++ b/reference/docs-conceptual/samples/Performing-Networking-Tasks.md @@ -8,7 +8,7 @@ ms.assetid: a43cc55f-70c1-45c8-9467-eaad0d57e3b5 Because TCP/IP is the most commonly used network protocol, most low-level network protocol administration tasks involve TCP/IP. In this section, we use Windows PowerShell and WMI to do these tasks. -### Listing IP Addresses for a Computer +## Listing IP Addresses for a Computer To get all IP addresses in use on the local computer, use the following command: @@ -42,7 +42,7 @@ IPAddress Property System.String[] IPAddress {get;} The IPAddress property for each network adapter is actually an array. The braces in the definition indicate that **IPAddress** is not a **System.String** value, but an array of **System.String** values. -### Listing IP Configuration Data +## Listing IP Configuration Data To display detailed IP configuration data for each network adapter, use the following command: @@ -60,7 +60,7 @@ Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true - This command returns detailed information about DHCP, DNS, routing, and other minor IP configuration properties. -### Pinging Computers +## Pinging Computers You can perform a simple ping against a computer using by **Win32_PingStatus**. The following command performs the ping, but returns lengthy output: @@ -100,7 +100,7 @@ Note that this technique for generating a range of addresses can be used elsewhe $ips = 1..254 | ForEach-Object -Process {'192.168.1.' + $_} ``` -### Retrieving Network Adapter Properties +## Retrieving Network Adapter Properties Earlier in this user's guide, we mentioned that you could retrieve general configuration properties by using **Win32_NetworkAdapterConfiguration**. Although not strictly TCP/IP information, network adapter information such as MAC addresses and adapter types can be useful for understanding what is going on with a computer. To get a summary of this information, use the following command: @@ -108,7 +108,7 @@ Earlier in this user's guide, we mentioned that you could retrieve general confi Get-WmiObject -Class Win32_NetworkAdapter -ComputerName . ``` -### Assigning the DNS Domain for a Network Adapter +## Assigning the DNS Domain for a Network Adapter To assign the DNS domain for automatic name resolution, use the **Win32_NetworkAdapterConfiguration SetDNSDomain** method. Because you assign the DNS domain for each network adapter configuration independently, you need to use a **ForEach-Object** statement to assign the domain to each adapter: @@ -124,11 +124,11 @@ You can filter the command by using the **Where-Object** cmdlet, instead of usin Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName . | Where-Object -FilterScript {$_.IPEnabled} | ForEach-Object -Process {$_.SetDNSDomain('fabrikam.com')} ``` -### Performing DHCP Configuration Tasks +## Performing DHCP Configuration Tasks Modifying DHCP details involves working with a set of network adapters, just as the DNS configuration does. There are several distinct actions you can perform by using WMI, and we will step through a few of the common ones. -#### Determining DHCP-Enabled Adapters +### Determining DHCP-Enabled Adapters To find the DHCP-enabled adapters on a computer, use the following command: @@ -142,7 +142,7 @@ To exclude adapters with IP configuration problems, you can retrieve only IP-ena Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=$true and DHCPEnabled=$true" -ComputerName . ``` -#### Retrieving DHCP Properties +### Retrieving DHCP Properties Because DHCP-related properties for an adapter generally begin with "DHCP," you can use the Property parameter of Format-Table to display only those properties: @@ -150,7 +150,7 @@ Because DHCP-related properties for an adapter generally begin with "DHCP," you Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=$true" -ComputerName . | Format-Table -Property DHCP* ``` -#### Enabling DHCP on Each Adapter +### Enabling DHCP on Each Adapter To enable DHCP on all adapters, use the following command: @@ -160,7 +160,7 @@ Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true - You can use the **Filter** statement "IPEnabled=$true and DHCPEnabled=$false" to avoid enabling DHCP where it is already enabled, but omitting this step will not cause errors. -#### Releasing and Renewing DHCP Leases on Specific Adapters +### Releasing and Renewing DHCP Leases on Specific Adapters The **Win32_NetworkAdapterConfiguration** class has **ReleaseDHCPLease** and **RenewDHCPLease** methods. Both are used in the same way. In general, use these methods if you only need to release or renew addresses for an adapter on a specific subnet. The easiest way to filter adapters on a subnet is to choose only the adapter configurations that use the gateway for that subnet. For example, the following command releases all DHCP leases on adapters on the local computer that are obtaining DHCP leases from 192.168.1.254: @@ -177,7 +177,7 @@ Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=$true > [!NOTE] > When using these methods on a remote computer, be aware that you can lose access to the remote system if you are connected to it through the adapter with the released or renewed lease. -#### Releasing and Renewing DHCP Leases on All Adapters +### Releasing and Renewing DHCP Leases on All Adapters You can perform global DHCP address releases or renewals on all adapters by using the **Win32_NetworkAdapterConfiguration** methods, **ReleaseDHCPLeaseAll** and **RenewDHCPLeaseAll**. However, the command must apply to the WMI class, rather than a particular adapter, because releasing and renewing leases globally is performed on the class, not on a specific adapter. @@ -199,7 +199,7 @@ You can use the same command format to invoke the **RenewDHCPLeaseAll** method: ( Get-WmiObject -List | Where-Object -FilterScript {$_.Name -eq 'Win32_NetworkAdapterConfiguration'} ).RenewDHCPLeaseAll() ``` -### Creating a Network Share +## Creating a Network Share To create a network share, use the **Win32_Share Create** method: @@ -213,7 +213,7 @@ You can also create the share by using **net share** in Windows PowerShell: net share tempshare=c:\temp /users:25 /remark:"test share of the temp folder" ``` -### Removing a Network Share +## Removing a Network Share You can remove a network share with **Win32_Share**, but the process is slightly different from creating a share, because you need to retrieve the specific share to be removed, rather than the **Win32_Share** class. The following statement deletes the share "TempShare": @@ -229,7 +229,7 @@ PS> net share tempshare /delete tempshare was deleted successfully. ``` -### Connecting a Windows Accessible Network Drive +## Connecting a Windows Accessible Network Drive The **New-PSDrive** cmdlets creates a Windows PowerShell drive, but drives created this way are available only to Windows PowerShell. To create a new networked drive, you can use the **WScript.Network** COM object. The following command maps the share \\\\FPS01\\users to local drive B: diff --git a/reference/docs-conceptual/samples/Redirecting-Data-with-Out---Cmdlets.md b/reference/docs-conceptual/samples/Redirecting-Data-with-Out---Cmdlets.md index 99e7e2a49fb0..f886c7a68033 100644 --- a/reference/docs-conceptual/samples/Redirecting-Data-with-Out---Cmdlets.md +++ b/reference/docs-conceptual/samples/Redirecting-Data-with-Out---Cmdlets.md @@ -62,7 +62,7 @@ This applies to all of the **Out** cmdlets. An **Out** cmdlet should always appe > [!NOTE] > All the **Out** cmdlets render output as text, using the formatting in effect for the console window, including line length limits. -#### Paging Console Output (Out-Host) +## Paging Console Output (Out-Host) By default, Windows PowerShell sends data to the host window, which is exactly what the Out-Host cmdlet does. The primary use for the Out-Host cmdlet is paging data as we discussed earlier. For example, the following command uses Out-Host to page the output of the Get-Command cmdlet: @@ -87,7 +87,7 @@ default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS ... ``` -#### Discarding Output (Out-Null) +## Discarding Output (Out-Null) The **Out-Null** cmdlet is designed to immediately discard any input it receives. This is useful for discarding unnecessary data that you get as a side-effect of running a command. When type the following command, you do not get anything back from the command: @@ -105,7 +105,7 @@ At line:1 char:12 + Get-Command <<<< Is-NotACommand | Out-Null ``` -#### Printing Data (Out-Printer) +## Printing Data (Out-Printer) You can print data by using the **Out-Printer** cmdlet. The **Out-Printer** cmdlet will use your default printer if you do not provide a printer name. You can use any Windows-based printer by specifying its display name. There is no need for any kind of printer port mapping or even a real physical printer. For example, if you have the Microsoft Office document imaging tools installed, you can send the data to an image file by typing: @@ -113,7 +113,7 @@ You can print data by using the **Out-Printer** cmdlet. The **Out-Printer** cmdl Get-Command Get-Command | Out-Printer -Name 'Microsoft Office Document Image Writer' ``` -#### Saving Data (Out-File) +## Saving Data (Out-File) You can send output to a file instead of the console window by using the **Out-File** cmdlet. The following command line sends a list of processes to the file **C:\\temp\\processlist.txt**: diff --git a/reference/docs-conceptual/samples/Removing-Objects-from-the-Pipeline--Where-Object-.md b/reference/docs-conceptual/samples/Removing-Objects-from-the-Pipeline--Where-Object-.md index 39f816f1e77c..739a182f8271 100644 --- a/reference/docs-conceptual/samples/Removing-Objects-from-the-Pipeline--Where-Object-.md +++ b/reference/docs-conceptual/samples/Removing-Objects-from-the-Pipeline--Where-Object-.md @@ -10,7 +10,7 @@ In Windows PowerShell, you often generate and pass along more objects to a pipel Windows PowerShell includes a `Where-Object` cmdlet that allows you to test each object in the pipeline and only pass it along the pipeline if it meets a particular test condition. Objects that do not pass the test are removed from the pipeline. You supply the test condition as the value of the `Where-Object` **FilterScript** parameter. -### Performing Simple Tests with Where-Object +## Performing Simple Tests with Where-Object The value of **FilterScript** is a *script block* - one or more Windows PowerShell commands surrounded by braces {} - that evaluates to true or false. These script blocks can be very simple, but creating them requires knowing about another Windows PowerShell concept, comparison operators. A comparison operator compares the items that appear on each side of it. Comparison operators begin with a '-' character and are followed by a name. Basic comparison operators work on almost any kind of object. The more advanced comparison operators might only work on text or arrays. @@ -40,7 +40,7 @@ PS> 1,2,3,4 | Where-Object -FilterScript {$_ -lt 3} 2 ``` -### Filtering Based on Object Properties +## Filtering Based on Object Properties Since `$_` refers to the current pipeline object, we can access its properties for our tests. diff --git a/reference/docs-conceptual/samples/Using-Format-Commands-to-Change-Output-View.md b/reference/docs-conceptual/samples/Using-Format-Commands-to-Change-Output-View.md index 7f7365f883fa..2ba9600e73c5 100644 --- a/reference/docs-conceptual/samples/Using-Format-Commands-to-Change-Output-View.md +++ b/reference/docs-conceptual/samples/Using-Format-Commands-to-Change-Output-View.md @@ -23,7 +23,7 @@ Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName In the rest of this section, we will explore how to use **Format** cmdlets to change the way the output of this command is displayed. -### Using Format-Wide for Single-Item Output +## Using Format-Wide for Single-Item Output The `Format-Wide` cmdlet, by default, displays only the default property of an object. The information associated with each object is displayed in a single column: @@ -50,7 +50,7 @@ List Table Wide ``` -#### Controlling Format-Wide Display with Column +### Controlling Format-Wide Display with Column With the `Format-Wide` cmdlet, you can only display a single property at a time. This makes it useful for displaying simple lists that show only one element per line. @@ -68,7 +68,7 @@ Table Wide ``` -### Using Format-List for a List View +## Using Format-List for a List View The **Format-List** cmdlet displays an object in the form of a listing, with each property labeled and displayed on a separate line: @@ -103,7 +103,7 @@ StartTime : 2006-05-24 13:54:28 Id : 3448 ``` -#### Getting Detailed Information by Using Format-List with Wildcards +### Getting Detailed Information by Using Format-List with Wildcards The **Format-List** cmdlet lets you use a wildcard as the value of its **Property** parameter. This lets you display detailed information. Often, objects include more information than you need, which is why Windows PowerShell does not show all property values by default. To show all of properties of an object, use the **Format-List -Property \*** command. The following command generates over 60 lines of output for a single process: @@ -113,7 +113,7 @@ Get-Process -Name powershell | Format-List -Property * Although the **Format-List** command is useful for showing detail, if you want an overview of output that includes many items, a simpler tabular view is often more useful. -### Using Format-Table for Tabular Output +## Using Format-Table for Tabular Output If you use the **Format-Table** cmdlet with no property names specified to format the output of the **Get-Process** command, you get exactly the same output as you do without performing any formatting. The reason is that processes are usually displayed in a tabular format, as are most Windows PowerShell objects. @@ -126,7 +126,7 @@ Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName 332 9 23140 632 141 1.06 3448 powershell ``` -#### Improving Format-Table Output (AutoSize) +### Improving Format-Table Output (AutoSize) Although a tabular view is useful for displaying a lot of comparable information, it may be difficult to interpret if the display is too narrow for the data. For example, if you try to display process path, ID, name, and company, you get truncated output for the process path and the company column: @@ -176,7 +176,7 @@ Microsoft Corporation C:\Program Files\Windows PowerShell\v1.0\powershell.exe 6 In the output above, the ID column is truncated to make it fit into the listing, and the column headings are stacked up. Automatically resizing the columns does not always do what you want. -#### Wrapping Format-Table Output in Columns (Wrap) +### Wrapping Format-Table Output in Columns (Wrap) You can force lengthy **Format-Table** data to wrap within its display column by using the **Wrap** parameter. Using the **Wrap** parameter alone will not necessarily do what you expect, since it uses default settings if you do not also specify **AutoSize**: @@ -219,7 +219,7 @@ C:\Program Files\Windows PowerShell\v1.0\powershell.exe 2836 Microsoft Corporat ion ``` -#### Organizing Table Output (-GroupBy) +### Organizing Table Output (-GroupBy) Another useful parameter for tabular output control is **GroupBy**. Longer tabular listings in particular may be hard to compare. The **GroupBy** parameter groups output based on a property value. For example, we can group processes by company for easier inspection, omitting the company value from the property listing: diff --git a/reference/docs-conceptual/samples/Using-Static-Classes-and-Methods.md b/reference/docs-conceptual/samples/Using-Static-Classes-and-Methods.md index 4ac0e2f1556f..5ed6930a49c7 100644 --- a/reference/docs-conceptual/samples/Using-Static-Classes-and-Methods.md +++ b/reference/docs-conceptual/samples/Using-Static-Classes-and-Methods.md @@ -5,6 +5,7 @@ title: Using Static Classes and Methods ms.assetid: 418ad766-afa6-4b8c-9a44-471889af7fd9 --- # Using Static Classes and Methods + Not all .NET Framework classes can be created by using **New-Object**. For example, if you try to create a **System.Environment** or a **System.Math** object with **New-Object**, you will get the following error messages: ``` @@ -23,10 +24,12 @@ At line:1 char:11 These errors occur because there is no way to create a new object from these classes. These classes are reference libraries of methods and properties that do not change state. You don't need to create them, you simply use them. Classes and methods such as these are called *static classes* because they are not created, destroyed, or changed. To make this clear we will provide examples that use static classes. -### Getting Environment Data with System.Environment +## Getting Environment Data with System.Environment + Usually, the first step in working with an object in Windows PowerShell is to use Get-Member to find out what members it contains. With static classes, the process is a little different because the actual class is not an object. -#### Referring to the Static System.Environment Class +### Referring to the Static System.Environment Class + You can refer to a static class by surrounding the class name with square brackets. For example, you can refer to **System.Environment** by typing the name within brackets. Doing so displays some generic type information: ``` @@ -83,7 +86,7 @@ TickCount ExitCode We can now select properties to view from System.Environment. -#### Displaying Static Properties of System.Environment +### Displaying Static Properties of System.Environment The properties of System.Environment are also static, and must be specified in a different way than normal properties. We use **::** to indicate to Windows PowerShell that we want to work with a static method or property. To see the command that was used to launch Windows PowerShell, we check the **CommandLine** property by typing: @@ -109,7 +112,7 @@ PS> [System.Environment]::HasShutdownStarted False ``` -### Doing Math with System.Math +## Doing Math with System.Math The System.Math static class is useful for performing some mathematical operations. The important members of **System.Math** are mostly methods, which we can display by using **Get-Member**. diff --git a/reference/docs-conceptual/samples/Working-With-Files-Folders-and-Registry-Keys.md b/reference/docs-conceptual/samples/Working-With-Files-Folders-and-Registry-Keys.md index c6a21846a690..0ea834da1a93 100644 --- a/reference/docs-conceptual/samples/Working-With-Files-Folders-and-Registry-Keys.md +++ b/reference/docs-conceptual/samples/Working-With-Files-Folders-and-Registry-Keys.md @@ -8,7 +8,7 @@ ms.assetid: e6cf87aa-b5f8-48d5-a75a-7cb7ecb482dc Windows PowerShell uses the noun **Item** to refer to items found on a Windows PowerShell drive. When dealing with the Windows PowerShell FileSystem provider, an **Item** might be a file, a folder, or the Windows PowerShell drive. Listing and working with these items is a critical basic task in most administrative settings, so we want to discuss these tasks in detail. -### Enumerating Files, Folders, and Registry Keys (Get-ChildItem) +## Enumerating Files, Folders, and Registry Keys (Get-ChildItem) Since getting a collection of items from a particular location is such a common task, the **Get-ChildItem** cmdlet is designed specifically to return all items found within a container such as a folder. @@ -36,7 +36,7 @@ Get-Command -Name Get-ChildItem -Syntax These parameters can be mixed and matched to get highly customized output. -#### Listing all Contained Items (-Recurse) +### Listing all Contained Items (-Recurse) To see both the items inside a Windows folder and any items that are contained within the subfolders, use the **Recurse** parameter of **Get-ChildItem**. The listing displays everything within the Windows folder and the items in its subfolders. For example: @@ -51,7 +51,7 @@ Mode LastWriteTime Length Name ... ``` -#### Filtering Items by Name (-Name) +### Filtering Items by Name (-Name) To display only the names of items, use the **Name** parameter of **Get-Childitem**: @@ -63,7 +63,7 @@ assembly ... ``` -#### Forcibly Listing Hidden Items (-Force) +### Forcibly Listing Hidden Items (-Force) Items that are normally invisible in File Explorer or Cmd.exe are not displayed in the output of a **Get-ChildItem** command. To display hidden items, use the **Force** parameter of **Get-ChildItem**. For example: @@ -73,7 +73,7 @@ Get-ChildItem -Path C:\Windows -Force This parameter is named Force because you can forcibly override the normal behavior of the **Get-ChildItem** command. Force is a widely used parameter that forces an action that a cmdlet would not normally perform, although it will not perform any action that compromises the security of the system. -#### Matching Item Names with Wildcards +### Matching Item Names with Wildcards **The Get-ChildItem** command accepts wildcards in the path of the items to list. @@ -116,7 +116,7 @@ To find all files whose names begin with **x** or **z**, type: Get-ChildItem -Path C:\Windows\[xz]* ``` -#### Excluding Items (-Exclude) +### Excluding Items (-Exclude) You can exclude specific items by using the **Exclude** parameter of Get-ChildItem. This lets you perform complex filtering in a single statement. @@ -141,7 +141,7 @@ Mode LastWriteTime Length Name -a--- 2004-08-04 8:00 AM 18432 wtsapi32.dll ``` -#### Mixing Get-ChildItem Parameters +### Mixing Get-ChildItem Parameters You can use several of the parameters of the **Get-ChildItem** cmdlet in the same command. Before you mix parameters, be sure that you understand wildcard matching. For example, the following command returns no results: diff --git a/reference/docs-conceptual/samples/Working-with-Files-and-Folders.md b/reference/docs-conceptual/samples/Working-with-Files-and-Folders.md index 6f8dbe2a1c8e..2d5c7b5549af 100644 --- a/reference/docs-conceptual/samples/Working-with-Files-and-Folders.md +++ b/reference/docs-conceptual/samples/Working-with-Files-and-Folders.md @@ -8,7 +8,7 @@ ms.assetid: c0ceb96b-e708-45f3-803b-d1f61a48f4c1 Navigating through Windows PowerShell drives and manipulating the items on them is similar to manipulating files and folders on Windows physical disk drives. This section discusses how to deal with specific file and folder manipulation tasks using PowerShell. -### Listing All the Files and Folders Within a Folder +## Listing All the Files and Folders Within a Folder You can get all items directly within a folder by using **Get-ChildItem**. Add the optional **Force** parameter to display hidden or system items. For example, this command displays the direct contents of Windows PowerShell Drive C (which is the same as the Windows physical drive C): @@ -30,7 +30,7 @@ The following command finds all executables within the Program Files folder that Get-ChildItem -Path $env:ProgramFiles -Recurse -Include *.exe | Where-Object -FilterScript {($_.LastWriteTime -gt '2005-10-01') -and ($_.Length -ge 1mb) -and ($_.Length -le 10mb)} ``` -### Copying Files and Folders +## Copying Files and Folders Copying is done with **Copy-Item**. The following command backs up C:\\boot.ini to C:\\boot.bak: @@ -64,7 +64,7 @@ You can still use other tools to perform file system copies. XCOPY, ROBOCOPY, an (New-Object -ComObject Scripting.FileSystemObject).CopyFile('C:\boot.ini', 'C:\boot.bak') ``` -### Creating Files and Folders +## Creating Files and Folders Creating new items works the same on all Windows PowerShell providers. If a Windows PowerShell provider has more than one type of item—for example, the FileSystem Windows PowerShell provider distinguishes between directories and files—you need to specify the item type. @@ -80,7 +80,7 @@ This command creates a new empty file C:\\temp\\New Folder\\file.txt New-Item -Path 'C:\temp\New Folder\file.txt' -ItemType File ``` -### Removing All Files and Folders Within a Folder +## Removing All Files and Folders Within a Folder You can remove contained items using **Remove-Item**, but you will be prompted to confirm the removal if the item contains anything else. For example, if you attempt to delete the folder C:\\temp\\DeleteMe that contains other items, Windows PowerShell prompts you for confirmation before deleting the folder: @@ -101,7 +101,7 @@ If you do not want to be prompted for each contained item, specify the **Recurse Remove-Item -Path C:\temp\DeleteMe -Recurse ``` -### Mapping a Local Folder as a Windows Accessible Drive +## Mapping a Local Folder as a Windows Accessible Drive You can also map a local folder, using the **subst** command. The following command creates a local drive P: rooted in the local Program Files directory: @@ -111,7 +111,7 @@ subst p: $env:programfiles Just as with network drives, drives mapped within Windows PowerShell using **subst** are immediately visible to the Windows PowerShell shell. -### Reading a Text File into an Array +## Reading a Text File into an Array One of the more common storage formats for text data is in a file with separate lines treated as distinct data elements. The **Get-Content** cmdlet can be used to read an entire file in one step, as shown here: diff --git a/reference/docs-conceptual/samples/Working-with-Printers.md b/reference/docs-conceptual/samples/Working-with-Printers.md index ab986dc113cc..cc7abdd12702 100644 --- a/reference/docs-conceptual/samples/Working-with-Printers.md +++ b/reference/docs-conceptual/samples/Working-with-Printers.md @@ -8,7 +8,7 @@ ms.assetid: 4f29ead3-f83b-4706-ac3e-f2154ff38dc5 You can use Windows PowerShell to manage printers by using WMI and the WScript.Network COM object from WSH. We will use a mix of both tools to demonstrate specific tasks. -### Listing Printer Connections +## Listing Printer Connections The simplest way to list the printers installed on a computer is to use the WMI **Win32_Printer** class: @@ -24,7 +24,7 @@ You can also list the printers by using the **WScript.Network** COM object that Because this command returns a simple string collection of port names and printer device names without any distinguishing labels, it is not easy to interpret. -### Adding a Network Printer +## Adding a Network Printer To add a new network printer, use **WScript.Network**: @@ -32,7 +32,7 @@ To add a new network printer, use **WScript.Network**: (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\Printserver01\Xerox5") ``` -### Setting a Default Printer +## Setting a Default Printer To use WMI to set the default printer, find the printer in the **Win32_Printer** collection and then invoke the **SetDefaultPrinter** method: @@ -46,7 +46,7 @@ To use WMI to set the default printer, find the printer in the **Win32_Printer** (New-Object -ComObject WScript.Network).SetDefaultPrinter('HP LaserJet 5Si') ``` -### Removing a Printer Connection +## Removing a Printer Connection To remove a printer connection, use the **WScript.Network RemovePrinterConnection** method: diff --git a/reference/docs-conceptual/samples/Working-with-Registry-Entries.md b/reference/docs-conceptual/samples/Working-with-Registry-Entries.md index c0caaf0d1974..50098f3e6ef3 100644 --- a/reference/docs-conceptual/samples/Working-with-Registry-Entries.md +++ b/reference/docs-conceptual/samples/Working-with-Registry-Entries.md @@ -9,7 +9,7 @@ ms.assetid: fd254570-27ac-4cc9-81d4-011afd29b7dc Because registry entries are properties of keys and, as such, cannot be directly browsed, we need to take a slightly different approach when working with them. -### Listing Registry Entries +## Listing Registry Entries There are many different ways to examine registry entries. The simplest way is to get the property names associated with a key. For example, to see the names of the entries in the registry key @@ -92,7 +92,7 @@ Path expansion works the same as it does within the file system, so from this lo the **ItemProperty** listing for `HKLM:\SOFTWARE\Microsoft\Windows\Help` by using `Get-ItemProperty -Path ..\Help`. -### Getting a Single Registry Entry +## Getting a Single Registry Entry If you want to retrieve a specific entry in a registry key, you can use one of several possible approaches. This example finds the value of **DevicePath** in @@ -150,7 +150,7 @@ such as "\\"). Append the property name to the item path with a \\ separator: %SystemRoot%\inf ``` -### Setting a Single Registry Entry +## Setting a Single Registry Entry If you want to change a specific entry in a registry key, you can use one of several possible approaches. This example modifies the **Path** entry under `HKEY_CURRENT_USER\Environment`. The @@ -190,7 +190,7 @@ reg add HKCU\Environment /v Path /d $newpath /f The operation completed successfully. ``` -### Creating New Registry Entries +## Creating New Registry Entries To add a new entry named "PowerShellPath" to the **CurrentVersion** key, use `New-ItemProperty` with the path to the key, the entry name, and the value of the entry. For this example, we will @@ -237,7 +237,7 @@ New-ItemProperty -Name PowerShellPath -PropertyType String -Value $PSHome ` You can also overwrite a pre-existing registry entry value by adding the **Force** parameter to any `New-ItemProperty` command. -### Renaming Registry Entries +## Renaming Registry Entries To rename the **PowerShellPath** entry to "PSHome," use `Rename-ItemProperty`: @@ -251,7 +251,7 @@ To display the renamed value, add the **PassThru** parameter to the command. Rename-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PowerShellPath -NewName PSHome -passthru ``` -### Deleting Registry Entries +## Deleting Registry Entries To delete both the PSHome and PowerShellPath registry entries, use `Remove-ItemProperty`: diff --git a/reference/docs-conceptual/samples/Working-with-Registry-Keys.md b/reference/docs-conceptual/samples/Working-with-Registry-Keys.md index 9d6f790baa2b..647c7c68ebb1 100644 --- a/reference/docs-conceptual/samples/Working-with-Registry-Keys.md +++ b/reference/docs-conceptual/samples/Working-with-Registry-Keys.md @@ -8,7 +8,7 @@ ms.assetid: 91bfaecd-8684-48b4-ad86-065dfe6dc90a Because registry keys are items on Windows PowerShell drives, working with them is very similar to working with files and folders. One critical difference is that every item on a registry-based Windows PowerShell drive is a container, just like a folder on a file system drive. However, registry entries and their associated values are properties of the items, not distinct items. -### Listing All Subkeys of a Registry Key +## Listing All Subkeys of a Registry Key You can show all items directly within a registry key by using **Get-ChildItem**. Add the optional **Force** parameter to display hidden or system items. For example, this command displays the items directly within Windows PowerShell drive HKCU:, which corresponds to the HKEY_CURRENT_USER registry hive: @@ -52,7 +52,7 @@ Get-ChildItem -Path hkcu:\ -Recurse Get-ChildItem -Path HKCU:\Software -Recurse | Where-Object -FilterScript {($_.SubKeyCount -le 1) -and ($_.ValueCount -eq 4) } ``` -### Copying Keys +## Copying Keys Copying is done with **Copy-Item**. The following command copies HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion and all of its properties to HKCU:\\, creating a new key named "CurrentVersion": @@ -68,7 +68,7 @@ Copy-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion' -Destination h You can still use other tools you already have available to perform filesystem copies. Any registry editing tools—including reg.exe, regini.exe, and regedit.exe—and COM objects that support registry editing (such as WScript.Shell and WMI's StdRegProv class) can be used from within Windows PowerShell. -### Creating Keys +## Creating Keys Creating new keys in the registry is simpler than creating a new item in a file system. Because all registry keys are containers, you do not need to specify the item type; you simply supply an explicit path, such as: @@ -82,7 +82,7 @@ You can also use a provider-based path to specify a key: New-Item -Path Registry::HKCU_DeleteMe ``` -### Deleting Keys +## Deleting Keys Deleting items is essentially the same for all providers. The following commands will silently remove items: @@ -91,7 +91,7 @@ Remove-Item -Path hkcu:\Software_DeleteMe Remove-Item -Path 'hkcu:\key with spaces in the name' ``` -### Removing All Keys Under a Specific Key +## Removing All Keys Under a Specific Key You can remove contained items by using **Remove-Item**, but you will be prompted to confirm the removal if the item contains anything else. For example, if we attempt to delete the HKCU:\\CurrentVersion subkey we created, we see this: diff --git a/reference/docs-conceptual/samples/Working-with-Software-Installations.md b/reference/docs-conceptual/samples/Working-with-Software-Installations.md index 9cfab85a64d3..20e8aae8a4b7 100644 --- a/reference/docs-conceptual/samples/Working-with-Software-Installations.md +++ b/reference/docs-conceptual/samples/Working-with-Software-Installations.md @@ -11,7 +11,7 @@ Applications that are designed to use Windows Installer can be accessed through > [!NOTE] > Applications that are installed by copying the application files to the computer usually cannot be managed by using techniques discussed here. You can manage these applications as files and folders by using the techniques discussed in the "Working With Files and Folders" section. -### Listing Windows Installer Applications +## Listing Windows Installer Applications To list the applications installed with the Windows Installer on a local or remote system, use the following simple WMI query: @@ -79,7 +79,7 @@ Get-WmiObject -Class Win32_Product -ComputerName . | Format-Wide -Column 1 Although we now have several ways to look at applications that used the Windows Installer for installation, we have not considered other applications. Because most standard applications register their uninstaller with Windows, we can work with those locally by finding them in the Windows registry. -### Listing All Uninstallable Applications +## Listing All Uninstallable Applications Although there is no guaranteed way to find every application on a system, it is possible to find all programs with listings displayed in the Add or Remove Programs dialog box. Add or Remove Programs finds these applications in the following registry key: @@ -136,7 +136,7 @@ SKC VC Name Property 0 24 {E38C00D0-A68B-4318-A8A6-F7... {AuthorizedCDFPrefix, Comments, Conta... ``` -### Installing Applications +## Installing Applications You can use the **Win32_Product** class to install Windows Installer packages, remotely or locally. @@ -151,7 +151,7 @@ When installing remotely, use a Universal Naming Convention (UNC) network path t Applications that do not use Windows Installer technology may have application-specific methods available for automated deployment. To determine whether there is a method for deployment automation, check the documentation for the application or consult the application vendor's support system. In some cases, even if the application vendor did not specifically design the application for installation automation, the installer software manufacturer may have some techniques for automation. -### Removing Applications +## Removing Applications Removing a Windows Installer package by using Windows PowerShell works in approximately the same way as installing a package. Here is an example that selects the package to uninstall based on its name; in some cases it may be easier to filter with the **IdentifyingNumber**: @@ -173,7 +173,7 @@ Get-ChildItem -Path Uninstall: | Where-Object -FilterScript { $_.GetValue('Displ However, these strings may not be directly usable from the Windows PowerShell prompt without some modification. -### Upgrading Windows Installer Applications +## Upgrading Windows Installer Applications To upgrade an application, you need to know the name of the application and the path to the application upgrade package. With that information, you can upgrade an application with a single Windows PowerShell command: