Updates from: 07/29/2021 03:16:09
Service Microsoft Docs article Related commit history on GitHub Change details
Microsoft.PowerShell.Core About Functions Advanced Parameters (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md
--- description: Explains how to add parameters to advanced functions.
-keywords: powershell,cmdlet
Locale: en-US Previously updated : 07/27/2021 Last updated : 07/28/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Functions Advanced Parameters
value is required.
from its default functionality to a less common or more complicated mode. The simplest behavior of a command should be the default behavior that does not require the use of switch parameters.-- Switch parameters should not be mandatory, since that defeats the purpose of
- a switch; a mandatory switch can only take one value. The only case where is
- is necessary to make a switch parameter mandatory is when it is needed to
- differentiate a parameter set. In this case, the switch parameter must be
- mandatory.
+- Switch parameters should not be mandatory since a switch, when used, can only
+ be `$true`. The only case where it is necessary to make a switch parameter
+ mandatory is when it is needed to differentiate a parameter set.
- Explicitly setting a switch from a boolean can be done with `-MySwitch:$boolValue` and in splatting with `$params = @{ MySwitch = $boolValue }`.
Microsoft.PowerShell.Utility Sort Object (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Utility/Sort-Object.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
keywords: powershell,cmdlet Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 08/10/2020 Last updated : 07/28/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/sort-object?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Sort-Object
Title: Sort-Object
# Sort-Object
-## SYNOPSIS
+## Synopsis
Sorts objects by property values.
-## SYNTAX
+## Syntax
### Default (Default)
Sort-Object [[-Property] <Object[]>] [-Descending] [-Unique] [-InputObject <psob
[-Culture <string>] [-CaseSensitive] [<CommonParameters>] ```
-## DESCRIPTION
+## Description
The `Sort-Object` cmdlet sorts objects in ascending or descending order based on object property
-values. If sort properties are not included in a command, PowerShell uses default sort properties
+values. If sort properties are not included in a command, PowerShell uses default sort properties
of the first input object. If the type of the input object has no default sort properties, PowerShell attempts to compare the objects themselves. For more information, see the [Notes](#notes) section.
tables to sort in ascending order, descending order, or a combination of sort or
sorted as case-sensitive or case-insensitive. Use the **Unique** parameter to eliminate duplicates from the output.
-## EXAMPLES
+## Examples
### Example 1: Sort the current directory by name
-This command sorts the files and subdirectories in a directory.
+This example sorts the files and subdirectories in a directory.
+```powershell
+Get-ChildItem -Path C:\Test | Sort-Object
```
-PS> Get-ChildItem -Path C:\Test | Sort-Object
+```Output
Directory: C:\Test Mode LastWriteTime Length Name
d----- 2/25/2019 18:24 Logs
``` The `Get-ChildItem` cmdlet gets the files and subdirectories from the directory specified by the
-**Path** parameter, **C:\Test**. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
+**Path** parameter, `C:\Test`. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
`Sort-Object` does not specify a property so the output is sorted by the default sort property, **Name**.
The `Get-ChildItem` cmdlet gets the files and subdirectories from the directory
This command displays the files in the current directory by length in ascending order.
+```powershell
+Get-ChildItem -Path C:\Test -File | Sort-Object -Property Length
```
-PS> Get-ChildItem -Path C:\Test -File | Sort-Object -Property Length
+```Output
Directory: C:\Test Mode LastWriteTime Length Name
the files by length in ascending order.
This example displays processes with the highest memory usage based on their working set (WS) size.
+```powershell
+Get-Process | Sort-Object -Property WS | Select-Object -Last 5
```
-PS> Get-Process | Sort-Object -Property WS | Select-Object -Last 5
+```Output
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName ------ ----- ----- ------ -- -- ----------- 136 193.92 217.11 889.16 87492 8 OUTLOOK
with the highest **WS** usage.
This command sorts the PowerShell session's **HistoryInfo** objects using the **Id** property. Each PowerShell session has its own command history.
+```powershell
+Get-History | Sort-Object -Property Id -Descending
```
-PS> Get-History | Sort-Object -Property Id -Descending
+```Output
Id CommandLine -- ----------- 10 Get-Command Sort-Object -Syntax
newest to oldest.
### Example 5: Use a hash table to sort properties in ascending and descending order
-This command uses two properties to sort the objects, **Status** and **DisplayName**. **Status** is
+This example uses two properties to sort the objects, **Status** and **DisplayName**. **Status** is
sorted in descending order and **DisplayName** is sorted in ascending order. A hash table is used to specify the **Property** parameter's value. The hash table uses an
see [about_Hash_Tables](../Microsoft.PowerShell.Core/About/about_Hash_Tables.md)
The **Status** property used in the hash table is an enumerated property. For more information, see [ServiceControllerStatus](/dotnet/api/system.serviceprocess.servicecontrollerstatus).
+```powershell
+Get-Service |
+ Sort-Object -Property @{Expression = "Status"; Descending = $true},
+ @{Expression = "DisplayName"; Descending = $false}
```
-PS C:\> Get-Service | Sort-Object -Property @{Expression = "Status"; Descending = $True}, @{Expression = "DisplayName"; Descending = $False}
+```Output
Status Name DisplayName ------ ---- ----------- Running Appinfo Application Information
the display names in alphabetical order.
This command sorts text files in descending order by the time span between **CreationTime** and **LastWriteTime**.
+```powershell
+Get-ChildItem -Path C:\Test\*.txt |
+ Sort-Object -Property {$_.CreationTime - $_.LastWriteTime} |
+ Format-Table CreationTime, LastWriteTime, FullName
```
-PS> Get-ChildItem -Path C:\Test\*.txt | Sort-Object -Property @{Expression = {$_.CreationTime - $_.LastWriteTime}; Descending = $False} | Format-Table CreationTime, LastWriteTime, FullName
+```Output
CreationTime LastWriteTime FullName ------------ ------------- -------- 11/21/2018 12:39:01 2/26/2019 08:59:36 C:\Test\test2.txt
CreationTime LastWriteTime FullName
2/25/2019 18:25:11 2/26/2019 12:08:47 C:\Test\Zsystemlog.txt 2/25/2019 18:25:11 2/26/2019 08:55:33 C:\Test\Bfile.txt 2/26/2019 08:46:59 2/26/2019 12:12:19 C:\Test\LogFile3.txt- ```
-The `Get-ChildItem` cmdlet uses the **Path** parameter to specify the directory **C:\Test** and all
+The `Get-ChildItem` cmdlet uses the **Path** parameter to specify the directory `C:\Test` and all
of the `*.txt` files. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
-`Sort-Object` uses the **Property** parameter with a hash table to determine each files time span
-between **CreationTime** and **LastWriteTime**. The **Descending** parameter is set to `$False` to
-sort in the order of longest to shortest time span.
+`Sort-Object` uses the **Property** parameter with a scriptblock to determine each files time span
+between **CreationTime** and **LastWriteTime**.
### Example 7: Sort names in a text file
This example shows how to sort a list from a text file. The original file is dis
unsorted list. `Sort-Object` sorts the contents and then sorts the contents with the **Unique** parameter that removes duplicates.
+```powershell
+# All items unsorted
+Get-Content -Path C:\Test\ServerNames.txt
```
-PS> Get-Content -Path C:\Test\ServerNames.txt
+
+```Output
localhost server01 server25
LOCALHOST
Server19 server3 localhost
+```
-PS> Get-Content -Path C:\Test\ServerNames.txt | Sort-Object
+```powershell
+# All items sorted
+Get-Content -Path C:\Test\ServerNames.txt | Sort-Object
localhost LOCALHOST localhost
server01
Server19 server25 server3
+```
+
+```powershell
+# Unique filtered items sorted
+Get-Content -Path C:\Test\ServerNames.txt | Sort-Object -Unique
+```
-PS> Get-Content -Path C:\Test\ServerNames.txt | Sort-Object -Unique
+```Output
localhost server01 Server19
server3
``` The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names.
+file `ServerNames.txt` contains an unsorted list of computer names.
The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names. The objects are sent down the
+file `ServerNames.txt` contains an unsorted list of computer names. The objects are sent down the
pipeline to the `Sort-Object` cmdlet. `Sort-Object` sorts the list in the default order, ascending. The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names. The objects are sent down the
+file `ServerNames.txt` contains an unsorted list of computer names. The objects are sent down the
pipeline to the `Sort-Object` cmdlet. `Sort-Object` uses the **Unique** parameter to remove duplicate computer names. The list is sorted in the default order, ascending.
integers. For these examples, the `ProductId.txt` file contains an unsorted list
In the first example, `Get-Content` gets the contents of the file and pipes lines to the `Sort-Object` cmdlet. `Sort-Object` sorts the string objects in ascending order.
+```powershell
+# String sorted
+Get-Content -Path C:\Test\ProductId.txt | Sort-Object
```
-PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object
+
+```Output
0 1 12345
PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object
77 88 99999
+```
-PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object {[int]$_}
+```powershell
+# Integer sorted
+Get-Content -Path C:\Test\ProductId.txt | Sort-Object {[int]$_}
+```
+
+```Output
0 1 2
sample code, `[int]` converts the string to an integer and `$_` represents each
down the pipeline. The integer objects are sent down the pipeline to the `Sort-Object` cmdlet. `Sort-Object` sorts the integer objects in numeric order.
-The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ProductId.txt** contains an unsorted list of product numbers. The string objects are sent
-down the pipeline to the `ForEach-Object` cmdlet. `ForEach-Object` uses a script block to convert
-the strings to integers. In the sample code, `[int]` converts the string to an integer and `$_`
-represents each string as it comes down the pipeline. The integer objects are sent down the pipeline
-to the `Sort-Object` cmdlet. `Sort-Object` sorts the integer objects in numeric order.
-## PARAMETERS
+## Parameters
### -CaseSensitive
property. This process continues until there are no more specified properties or
objects. The **Property** parameter's value can be a calculated property. To create a calculated property,
-use a hash table.
+use a scriptblock or a hashtable.
Valid keys for a hash table are as follows:
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
-## INPUTS
+## Inputs
### System.Management.Automation.PSObject You can pipe the objects to be sorted to `Sort-Object`.
-## OUTPUTS
+## Outputs
### System.Management.Automation.PSObject `Sort-Object` returns the sorted objects.
-## NOTES
+## Notes
The `Sort-Object` cmdlet sorts objects based on properties specified in the command or the default sort properties for the object type. Default sort properties are defined using the `PropertySet`
values. For Windows services, **Stopped** has a value of **1** and **Running** h
**Stopped** is sorted before **Running** because of the enumerated values. For more information, see [ServiceControllerStatus](/dotnet/api/system.serviceprocess.servicecontrollerstatus).
-## RELATED LINKS
+## Related links
[about_Calculated_Properties](../Microsoft.PowerShell.Core/About/about_Calculated_Properties.md)
Microsoft.PowerShell.Core About Functions Advanced Parameters (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md
--- description: Explains how to add parameters to advanced functions.
-keywords: powershell,cmdlet
Locale: en-US Previously updated : 07/27/2021 Last updated : 07/28/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Functions Advanced Parameters
value is required.
from its default functionality to a less common or more complicated mode. The simplest behavior of a command should be the default behavior that does not require the use of switch parameters.-- Switch parameters should not be mandatory, since that defeats the purpose of
- a switch; a mandatory switch can only take one value. The only case where is
- is necessary to make a switch parameter mandatory is when it is needed to
- differentiate a parameter set. In this case, the switch parameter must be
- mandatory.
+- Switch parameters should not be mandatory since a switch, when used, can only
+ be `$true`. The only case where it is necessary to make a switch parameter
+ mandatory is when it is needed to differentiate a parameter set.
- Explicitly setting a switch from a boolean can be done with `-MySwitch:$boolValue` and in splatting with `$params = @{ MySwitch = $boolValue }`.
Microsoft.PowerShell.Utility Sort Object (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Utility/Sort-Object.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
keywords: powershell,cmdlet Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 08/10/2020 Last updated : 07/28/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/sort-object?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Sort-Object
Title: Sort-Object
# Sort-Object
-## SYNOPSIS
+## Synopsis
Sorts objects by property values.
-## SYNTAX
+## Syntax
### Default (Default)
Sort-Object [-Descending] [-Unique] -Bottom <Int32> [-InputObject <PSObject>] [[
[-Culture <String>] [-CaseSensitive] [<CommonParameters>] ```
-## DESCRIPTION
+## Description
The `Sort-Object` cmdlet sorts objects in ascending or descending order based on object property values. If sort properties are not included in a command, PowerShell uses default sort properties
tables to sort in ascending order, descending order, or a combination of sort or
sorted as case-sensitive or case-insensitive. Use the **Unique** parameter to eliminate duplicates from the output.
-## EXAMPLES
+## Examples
### Example 1: Sort the current directory by name This example sorts the files and subdirectories in a directory.
+```powershell
+Get-ChildItem -Path C:\Test | Sort-Object
```
-PS> Get-ChildItem -Path C:\Test | Sort-Object
+```Output
Directory: C:\Test Mode LastWriteTime Length Name
d----- 2/25/2019 18:24 Logs
``` The `Get-ChildItem` cmdlet gets the files and subdirectories from the directory specified by the
-**Path** parameter, **C:\Test**. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
+**Path** parameter, `C:\Test`. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
`Sort-Object` does not specify a property so the output is sorted by the default sort property, **Name**.
The `Get-ChildItem` cmdlet gets the files and subdirectories from the directory
This command displays the files in the current directory by length in ascending order.
+```powershell
+Get-ChildItem -Path C:\Test -File | Sort-Object -Property Length
```
-PS> Get-ChildItem -Path C:\Test -File | Sort-Object -Property Length
+```Output
Directory: C:\Test Mode LastWriteTime Length Name
the files by length in ascending order.
This example displays processes with the highest memory usage based on their working set (WS) size.
+```powershell
+Get-Process | Sort-Object -Property WS | Select-Object -Last 5
```
-PS> Get-Process | Sort-Object -Property WS | Select-Object -Last 5
+```Output
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName ------ ----- ----- ------ -- -- ----------- 136 193.92 217.11 889.16 87492 8 OUTLOOK
example, `Get-Process | Sort-Object -Property WS -Bottom 5`.
This command sorts the PowerShell session's **HistoryInfo** objects using the **Id** property. Each PowerShell session has its own command history.
+```powershell
+Get-History | Sort-Object -Property Id -Descending
```
-PS> Get-History | Sort-Object -Property Id -Descending
+```Output
Id CommandLine -- ----------- 10 Get-Command Sort-Object -Syntax
see [about_Hash_Tables](../Microsoft.PowerShell.Core/About/about_Hash_Tables.md)
The **Status** property used in the hash table is an enumerated property. For more information, see [ServiceControllerStatus](/dotnet/api/system.serviceprocess.servicecontrollerstatus).
+```powershell
+Get-Service |
+ Sort-Object -Property @{Expression = "Status"; Descending = $true},
+ @{Expression = "DisplayName"; Descending = $false}
```
-PS C:\> Get-Service | Sort-Object -Property @{Expression = "Status"; Descending = $True}, @{Expression = "DisplayName"; Descending = $False}
+```Output
Status Name DisplayName ------ ---- ----------- Running Appinfo Application Information
the display names in alphabetical order.
This command sorts text files in descending order by the time span between **CreationTime** and **LastWriteTime**.
+```powershell
+Get-ChildItem -Path C:\Test\*.txt |
+ Sort-Object -Property {$_.CreationTime - $_.LastWriteTime} |
+ Format-Table CreationTime, LastWriteTime, FullName
```
-PS> Get-ChildItem -Path C:\Test\*.txt | Sort-Object -Property @{Expression = {$_.CreationTime - $_.LastWriteTime}; Descending = $False} | Format-Table CreationTime, LastWriteTime, FullName
+```Output
CreationTime LastWriteTime FullName ------------ ------------- -------- 11/21/2018 12:39:01 2/26/2019 08:59:36 C:\Test\test2.txt
CreationTime LastWriteTime FullName
2/26/2019 08:46:59 2/26/2019 12:12:19 C:\Test\LogFile3.txt ```
-The `Get-ChildItem` cmdlet uses the **Path** parameter to specify the directory **C:\Test** and all
+The `Get-ChildItem` cmdlet uses the **Path** parameter to specify the directory `C:\Test` and all
of the `*.txt` files. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
-`Sort-Object` uses the **Property** parameter with a hash table to determine each files time span
-between **CreationTime** and **LastWriteTime**. The **Descending** parameter is set to `$False` to
-sort in the order of longest to shortest time span.
+`Sort-Object` uses the **Property** parameter with a scriptblock to determine each files time span
+between **CreationTime** and **LastWriteTime**.
### Example 7: Sort names in a text file
This example shows how to sort a list from a text file. The original file is dis
unsorted list. `Sort-Object` sorts the contents and then sorts the contents with the **Unique** parameter that removes duplicates.
+```powershell
+# All items unsorted
+Get-Content -Path C:\Test\ServerNames.txt
```
-PS> Get-Content -Path C:\Test\ServerNames.txt
+
+```Output
localhost server01 server25
LOCALHOST
Server19 server3 localhost
+```
-PS> Get-Content -Path C:\Test\ServerNames.txt | Sort-Object
+```powershell
+# All items sorted
+Get-Content -Path C:\Test\ServerNames.txt | Sort-Object
localhost LOCALHOST localhost
server01
Server19 server25 server3
+```
+
+```powershell
+# Unique filtered items sorted
+Get-Content -Path C:\Test\ServerNames.txt | Sort-Object -Unique
+```
-PS> Get-Content -Path C:\Test\ServerNames.txt | Sort-Object -Unique
+```Output
localhost server01 Server19
server3
``` The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names.
+file `ServerNames.txt` contains an unsorted list of computer names.
The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names. The objects are sent down the
+file `ServerNames.txt` contains an unsorted list of computer names. The objects are sent down the
pipeline to the `Sort-Object` cmdlet. `Sort-Object` sorts the list in the default order, ascending. The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names. The objects are sent down the
+file `ServerNames.txt` contains an unsorted list of computer names. The objects are sent down the
pipeline to the `Sort-Object` cmdlet. `Sort-Object` uses the **Unique** parameter to remove duplicate computer names. The list is sorted in the default order, ascending.
integers. For these examples, the `ProductId.txt` file contains an unsorted list
In the first example, `Get-Content` gets the contents of the file and pipes lines to the `Sort-Object` cmdlet. `Sort-Object` sorts the string objects in ascending order.
+```powershell
+# String sorted
+Get-Content -Path C:\Test\ProductId.txt | Sort-Object
```
-PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object
+
+```Output
0 1 12345
PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object
77 88 99999
+```
+
+```powershell
+# Integer sorted
+Get-Content -Path C:\Test\ProductId.txt | Sort-Object {[int]$_}
+```
-PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object {[int]$_}
+```Output
0 1 2
are sorting the numbers one through 20 by the their value 'modulo 3'. The modulo
zero to two. ```powershell
-PS> 1..20 |Sort-Object {$_ % 3}
+1..20 |Sort-Object {$_ % 3}
+```
+
+```Output
18 3 15
PS> 1..20 |Sort-Object {$_ % 3}
17 2 20
+```
+
+```powershell
+1..20 |Sort-Object {$_ % 3} -Stable
+```
-PS> 1..20 |Sort-Object {$_ % 3} -Stable
+```Output
3 6 9
The output from the first sort is correctly grouped by the modulus value but the
are not sorted within the modulus range. The second sort uses the **Stable** option to return a stable sort.
-## PARAMETERS
+## Parameters
### -Bottom
property. This process continues until there are no more specified properties or
objects. The **Property** parameter's value can be a calculated property. To create a calculated property,
-use a hash table.
+use a scriptblock or a hashtable.
Valid keys for a hash table are as follows:
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
-## INPUTS
+## Inputs
### System.Management.Automation.PSObject You can pipe the objects to be sorted to `Sort-Object`.
-## OUTPUTS
+## Outputs
### System.Management.Automation.PSObject `Sort-Object` returns the sorted objects.
-## NOTES
+## Notes
The `Sort-Object` cmdlet sorts objects based on properties specified in the command or the default sort properties for the object type. Default sort properties are defined using the `PropertySet`
see [ServiceControllerStatus](/dotnet/api/system.serviceprocess.servicecontrolle
The performance of the sorting algorithm is slower when doing a stable sort.
-## RELATED LINKS
+## Related links
[about_Calculated_Properties](../Microsoft.PowerShell.Core/About/about_Calculated_Properties.md)
Microsoft.PowerShell.Core About Functions Advanced Parameters (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md
--- description: Explains how to add parameters to advanced functions.
-keywords: powershell,cmdlet
Locale: en-US Previously updated : 07/27/2021 Last updated : 07/28/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Functions Advanced Parameters
value is required.
from its default functionality to a less common or more complicated mode. The simplest behavior of a command should be the default behavior that does not require the use of switch parameters.-- Switch parameters should not be mandatory, since that defeats the purpose of
- a switch; a mandatory switch can only take one value. The only case where is
- is necessary to make a switch parameter mandatory is when it is needed to
- differentiate a parameter set. In this case, the switch parameter must be
- mandatory.
+- Switch parameters should not be mandatory since a switch, when used, can only
+ be `$true`. The only case where it is necessary to make a switch parameter
+ mandatory is when it is needed to differentiate a parameter set.
- Explicitly setting a switch from a boolean can be done with `-MySwitch:$boolValue` and in splatting with `$params = @{ MySwitch = $boolValue }`.
Microsoft.PowerShell.Utility Sort Object (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Utility/Sort-Object.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
keywords: powershell,cmdlet Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 08/10/2020 Last updated : 07/28/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/sort-object?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Sort-Object
Title: Sort-Object
# Sort-Object
-## SYNOPSIS
+## Synopsis
Sorts objects by property values.
-## SYNTAX
+## Syntax
### Default (Default)
Sort-Object [-Descending] [-Unique] -Bottom <Int32> [-InputObject <PSObject>] [[
[-Culture <String>] [-CaseSensitive] [<CommonParameters>] ```
-## DESCRIPTION
+## Description
The `Sort-Object` cmdlet sorts objects in ascending or descending order based on object property values. If sort properties are not included in a command, PowerShell uses default sort properties
tables to sort in ascending order, descending order, or a combination of sort or
sorted as case-sensitive or case-insensitive. Use the **Unique** parameter to eliminate duplicates from the output.
-## EXAMPLES
+## Examples
### Example 1: Sort the current directory by name This example sorts the files and subdirectories in a directory.
+```powershell
+Get-ChildItem -Path C:\Test | Sort-Object
```
-PS> Get-ChildItem -Path C:\Test | Sort-Object
+```Output
Directory: C:\Test Mode LastWriteTime Length Name
d----- 2/25/2019 18:24 Logs
``` The `Get-ChildItem` cmdlet gets the files and subdirectories from the directory specified by the
-**Path** parameter, **C:\Test**. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
+**Path** parameter, `C:\Test`. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
`Sort-Object` does not specify a property so the output is sorted by the default sort property, **Name**.
The `Get-ChildItem` cmdlet gets the files and subdirectories from the directory
This command displays the files in the current directory by length in ascending order.
+```powershell
+Get-ChildItem -Path C:\Test -File | Sort-Object -Property Length
```
-PS> Get-ChildItem -Path C:\Test -File | Sort-Object -Property Length
+```Output
Directory: C:\Test Mode LastWriteTime Length Name
the files by length in ascending order.
This example displays processes with the highest memory usage based on their working set (WS) size.
+```powershell
+Get-Process | Sort-Object -Property WS | Select-Object -Last 5
```
-PS> Get-Process | Sort-Object -Property WS | Select-Object -Last 5
+```Output
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName ------ ----- ----- ------ -- -- ----------- 136 193.92 217.11 889.16 87492 8 OUTLOOK
example, `Get-Process | Sort-Object -Property WS -Bottom 5`.
This command sorts the PowerShell session's **HistoryInfo** objects using the **Id** property. Each PowerShell session has its own command history.
+```powershell
+Get-History | Sort-Object -Property Id -Descending
```
-PS> Get-History | Sort-Object -Property Id -Descending
+```Output
Id CommandLine -- ----------- 10 Get-Command Sort-Object -Syntax
see [about_Hash_Tables](../Microsoft.PowerShell.Core/About/about_Hash_Tables.md)
The **Status** property used in the hash table is an enumerated property. For more information, see [ServiceControllerStatus](/dotnet/api/system.serviceprocess.servicecontrollerstatus).
+```powershell
+Get-Service |
+ Sort-Object -Property @{Expression = "Status"; Descending = $true},
+ @{Expression = "DisplayName"; Descending = $false}
```
-PS C:\> Get-Service | Sort-Object -Property @{Expression = "Status"; Descending = $True}, @{Expression = "DisplayName"; Descending = $False}
+```Output
Status Name DisplayName ------ ---- ----------- Running Appinfo Application Information
the display names in alphabetical order.
This command sorts text files in descending order by the time span between **CreationTime** and **LastWriteTime**.
+```powershell
+Get-ChildItem -Path C:\Test\*.txt |
+ Sort-Object -Property {$_.CreationTime - $_.LastWriteTime} |
+ Format-Table CreationTime, LastWriteTime, FullName
```
-PS> Get-ChildItem -Path C:\Test\*.txt | Sort-Object -Property @{Expression = {$_.CreationTime - $_.LastWriteTime}; Descending = $False} | Format-Table CreationTime, LastWriteTime, FullName
+```Output
CreationTime LastWriteTime FullName ------------ ------------- -------- 11/21/2018 12:39:01 2/26/2019 08:59:36 C:\Test\test2.txt
CreationTime LastWriteTime FullName
2/26/2019 08:46:59 2/26/2019 12:12:19 C:\Test\LogFile3.txt ```
-The `Get-ChildItem` cmdlet uses the **Path** parameter to specify the directory **C:\Test** and all
+The `Get-ChildItem` cmdlet uses the **Path** parameter to specify the directory `C:\Test` and all
of the `*.txt` files. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
-`Sort-Object` uses the **Property** parameter with a hash table to determine each files time span
-between **CreationTime** and **LastWriteTime**. The **Descending** parameter is set to `$False` to
-sort in the order of longest to shortest time span.
+`Sort-Object` uses the **Property** parameter with a scriptblock to determine each files time span
+between **CreationTime** and **LastWriteTime**.
### Example 7: Sort names in a text file
This example shows how to sort a list from a text file. The original file is dis
unsorted list. `Sort-Object` sorts the contents and then sorts the contents with the **Unique** parameter that removes duplicates.
+```powershell
+# All items unsorted
+Get-Content -Path C:\Test\ServerNames.txt
```
-PS> Get-Content -Path C:\Test\ServerNames.txt
+
+```Output
localhost server01 server25
LOCALHOST
Server19 server3 localhost
+```
-PS> Get-Content -Path C:\Test\ServerNames.txt | Sort-Object
+```powershell
+# All items sorted
+Get-Content -Path C:\Test\ServerNames.txt | Sort-Object
localhost LOCALHOST localhost
server01
Server19 server25 server3
+```
+
+```powershell
+# Unique filtered items sorted
+Get-Content -Path C:\Test\ServerNames.txt | Sort-Object -Unique
+```
-PS> Get-Content -Path C:\Test\ServerNames.txt | Sort-Object -Unique
+```Output
localhost server01 Server19
server3
``` The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names.
+file `ServerNames.txt` contains an unsorted list of computer names.
The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names. The objects are sent down the
+file `ServerNames.txt` contains an unsorted list of computer names. The objects are sent down the
pipeline to the `Sort-Object` cmdlet. `Sort-Object` sorts the list in the default order, ascending. The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names. The objects are sent down the
+file `ServerNames.txt` contains an unsorted list of computer names. The objects are sent down the
pipeline to the `Sort-Object` cmdlet. `Sort-Object` uses the **Unique** parameter to remove duplicate computer names. The list is sorted in the default order, ascending.
integers. For these examples, the `ProductId.txt` file contains an unsorted list
In the first example, `Get-Content` gets the contents of the file and pipes lines to the `Sort-Object` cmdlet. `Sort-Object` sorts the string objects in ascending order.
+```powershell
+# String sorted
+Get-Content -Path C:\Test\ProductId.txt | Sort-Object
```
-PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object
+
+```Output
0 1 12345
PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object
77 88 99999
+```
+
+```powershell
+# Integer sorted
+Get-Content -Path C:\Test\ProductId.txt | Sort-Object {[int]$_}
+```
-PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object {[int]$_}
+```Output
0 1 2
are sorting the numbers one through 20 by the their value 'modulo 3'. The modulo
zero to two. ```powershell
-PS> 1..20 |Sort-Object {$_ % 3}
+1..20 |Sort-Object {$_ % 3}
+```
+
+```Output
18 3 15
PS> 1..20 |Sort-Object {$_ % 3}
17 2 20
+```
+
+```powershell
+1..20 |Sort-Object {$_ % 3} -Stable
+```
-PS> 1..20 |Sort-Object {$_ % 3} -Stable
+```Output
3 6 9
The output from the first sort is correctly grouped by the modulus value but the
are not sorted within the modulus range. The second sort uses the **Stable** option to return a stable sort.
-## PARAMETERS
+## Parameters
### -Bottom
property. This process continues until there are no more specified properties or
objects. The **Property** parameter's value can be a calculated property. To create a calculated property,
-use a hash table.
+use a scriptblock or a hashtable.
Valid keys for a hash table are as follows:
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
-## INPUTS
+## Inputs
### System.Management.Automation.PSObject You can pipe the objects to be sorted to `Sort-Object`.
-## OUTPUTS
+## Outputs
### System.Management.Automation.PSObject `Sort-Object` returns the sorted objects.
-## NOTES
+## Notes
The `Sort-Object` cmdlet sorts objects based on properties specified in the command or the default sort properties for the object type. Default sort properties are defined using the `PropertySet`
see [ServiceControllerStatus](/dotnet/api/system.serviceprocess.servicecontrolle
The performance of the sorting algorithm is slower when doing a stable sort.
-## RELATED LINKS
+## Related links
[about_Calculated_Properties](../Microsoft.PowerShell.Core/About/about_Calculated_Properties.md)
Microsoft.PowerShell.Core About Functions Advanced Parameters (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md
--- description: Explains how to add parameters to advanced functions.
-keywords: powershell,cmdlet
Locale: en-US Previously updated : 07/27/2021 Last updated : 07/28/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Functions Advanced Parameters
value is required.
from its default functionality to a less common or more complicated mode. The simplest behavior of a command should be the default behavior that does not require the use of switch parameters.-- Switch parameters should not be mandatory, since that defeats the purpose of
- a switch; a mandatory switch can only take one value. The only case where is
- is necessary to make a switch parameter mandatory is when it is needed to
- differentiate a parameter set. In this case, the switch parameter must be
- mandatory.
+- Switch parameters should not be mandatory since a switch, when used, can only
+ be `$true`. The only case where it is necessary to make a switch parameter
+ mandatory is when it is needed to differentiate a parameter set.
- Explicitly setting a switch from a boolean can be done with `-MySwitch:$boolValue` and in splatting with `$params = @{ MySwitch = $boolValue }`.
Microsoft.PowerShell.Utility Sort Object (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Utility/Sort-Object.md
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility Previously updated : 08/10/2020 Last updated : 07/28/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/sort-object?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: Sort-Object
Title: Sort-Object
# Sort-Object
-## SYNOPSIS
+## Synopsis
Sorts objects by property values.
-## SYNTAX
+## Syntax
### Default (Default)
Sort-Object [-Descending] [-Unique] -Bottom <Int32> [-InputObject <PSObject>] [[
[-Culture <String>] [-CaseSensitive] [<CommonParameters>] ```
-## DESCRIPTION
+## Description
The `Sort-Object` cmdlet sorts objects in ascending or descending order based on object property values. If sort properties are not included in a command, PowerShell uses default sort properties
tables to sort in ascending order, descending order, or a combination of sort or
sorted as case-sensitive or case-insensitive. Use the **Unique** parameter to eliminate duplicates from the output.
-## EXAMPLES
+## Examples
### Example 1: Sort the current directory by name This example sorts the files and subdirectories in a directory.
+```powershell
+Get-ChildItem -Path C:\Test | Sort-Object
```
-PS> Get-ChildItem -Path C:\Test | Sort-Object
+```Output
Directory: C:\Test Mode LastWriteTime Length Name
d----- 2/25/2019 18:24 Logs
``` The `Get-ChildItem` cmdlet gets the files and subdirectories from the directory specified by the
-**Path** parameter, **C:\Test**. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
+**Path** parameter, `C:\Test`. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
`Sort-Object` does not specify a property so the output is sorted by the default sort property, **Name**.
The `Get-ChildItem` cmdlet gets the files and subdirectories from the directory
This command displays the files in the current directory by length in ascending order.
+```powershell
+Get-ChildItem -Path C:\Test -File | Sort-Object -Property Length
```
-PS> Get-ChildItem -Path C:\Test -File | Sort-Object -Property Length
+```Output
Directory: C:\Test Mode LastWriteTime Length Name
the files by length in ascending order.
This example displays processes with the highest memory usage based on their working set (WS) size.
+```powershell
+Get-Process | Sort-Object -Property WS | Select-Object -Last 5
```
-PS> Get-Process | Sort-Object -Property WS | Select-Object -Last 5
+```Output
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName ------ ----- ----- ------ -- -- ----------- 136 193.92 217.11 889.16 87492 8 OUTLOOK
example, `Get-Process | Sort-Object -Property WS -Bottom 5`.
This command sorts the PowerShell session's **HistoryInfo** objects using the **Id** property. Each PowerShell session has its own command history.
+```powershell
+Get-History | Sort-Object -Property Id -Descending
```
-PS> Get-History | Sort-Object -Property Id -Descending
+```Output
Id CommandLine -- ----------- 10 Get-Command Sort-Object -Syntax
see [about_Hash_Tables](../Microsoft.PowerShell.Core/About/about_Hash_Tables.md)
The **Status** property used in the hash table is an enumerated property. For more information, see [ServiceControllerStatus](/dotnet/api/system.serviceprocess.servicecontrollerstatus).
+```powershell
+Get-Service |
+ Sort-Object -Property @{Expression = "Status"; Descending = $true},
+ @{Expression = "DisplayName"; Descending = $false}
```
-PS C:\> Get-Service | Sort-Object -Property @{Expression = "Status"; Descending = $True}, @{Expression = "DisplayName"; Descending = $False}
+```Output
Status Name DisplayName ------ ---- ----------- Running Appinfo Application Information
the display names in alphabetical order.
This command sorts text files in descending order by the time span between **CreationTime** and **LastWriteTime**.
+```powershell
+Get-ChildItem -Path C:\Test\*.txt |
+ Sort-Object -Property {$_.CreationTime - $_.LastWriteTime} |
+ Format-Table CreationTime, LastWriteTime, FullName
```
-PS> Get-ChildItem -Path C:\Test\*.txt | Sort-Object -Property @{Expression = {$_.CreationTime - $_.LastWriteTime}; Descending = $False} | Format-Table CreationTime, LastWriteTime, FullName
+```Output
CreationTime LastWriteTime FullName ------------ ------------- -------- 11/21/2018 12:39:01 2/26/2019 08:59:36 C:\Test\test2.txt
CreationTime LastWriteTime FullName
2/26/2019 08:46:59 2/26/2019 12:12:19 C:\Test\LogFile3.txt ```
-The `Get-ChildItem` cmdlet uses the **Path** parameter to specify the directory **C:\Test** and all
+The `Get-ChildItem` cmdlet uses the **Path** parameter to specify the directory `C:\Test` and all
of the `*.txt` files. The objects are sent down the pipeline to the `Sort-Object` cmdlet.
-`Sort-Object` uses the **Property** parameter with a hash table to determine each files time span
-between **CreationTime** and **LastWriteTime**. The **Descending** parameter is set to `$False` to
-sort in the order of longest to shortest time span.
+`Sort-Object` uses the **Property** parameter with a scriptblock to determine each files time span
+between **CreationTime** and **LastWriteTime**.
### Example 7: Sort names in a text file
This example shows how to sort a list from a text file. The original file is dis
unsorted list. `Sort-Object` sorts the contents and then sorts the contents with the **Unique** parameter that removes duplicates.
+```powershell
+# All items unsorted
+Get-Content -Path C:\Test\ServerNames.txt
```
-PS> Get-Content -Path C:\Test\ServerNames.txt
+
+```Output
localhost server01 server25
LOCALHOST
Server19 server3 localhost
+```
-PS> Get-Content -Path C:\Test\ServerNames.txt | Sort-Object
+```powershell
+# All items sorted
+Get-Content -Path C:\Test\ServerNames.txt | Sort-Object
localhost LOCALHOST localhost
server01
Server19 server25 server3
+```
+
+```powershell
+# Unique filtered items sorted
+Get-Content -Path C:\Test\ServerNames.txt | Sort-Object -Unique
+```
-PS> Get-Content -Path C:\Test\ServerNames.txt | Sort-Object -Unique
+```Output
localhost server01 Server19
server3
``` The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names.
+file `ServerNames.txt` contains an unsorted list of computer names.
The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names. The objects are sent down the
+file `ServerNames.txt` contains an unsorted list of computer names. The objects are sent down the
pipeline to the `Sort-Object` cmdlet. `Sort-Object` sorts the list in the default order, ascending. The `Get-Content` cmdlet uses the **Path** parameter to specify the directory and file name. The
-file **ServerNames.txt** contains an unsorted list of computer names. The objects are sent down the
+file `ServerNames.txt` contains an unsorted list of computer names. The objects are sent down the
pipeline to the `Sort-Object` cmdlet. `Sort-Object` uses the **Unique** parameter to remove duplicate computer names. The list is sorted in the default order, ascending.
integers. For these examples, the `ProductId.txt` file contains an unsorted list
In the first example, `Get-Content` gets the contents of the file and pipes lines to the `Sort-Object` cmdlet. `Sort-Object` sorts the string objects in ascending order.
+```powershell
+# String sorted
+Get-Content -Path C:\Test\ProductId.txt | Sort-Object
```
-PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object
+
+```Output
0 1 12345
PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object
77 88 99999
+```
+
+```powershell
+# Integer sorted
+Get-Content -Path C:\Test\ProductId.txt | Sort-Object {[int]$_}
+```
-PS> Get-Content -Path C:\Test\ProductId.txt | Sort-Object {[int]$_}
+```Output
0 1 2
are sorting the numbers one through 20 by the their value 'modulo 3'. The modulo
zero to two. ```powershell
-PS> 1..20 |Sort-Object {$_ % 3}
+1..20 |Sort-Object {$_ % 3}
+```
+
+```Output
18 3 15
PS> 1..20 |Sort-Object {$_ % 3}
17 2 20
+```
+
+```powershell
+1..20 |Sort-Object {$_ % 3} -Stable
+```
-PS> 1..20 |Sort-Object {$_ % 3} -Stable
+```Output
3 6 9
The output from the first sort is correctly grouped by the modulus value but the
are not sorted within the modulus range. The second sort uses the **Stable** option to return a stable sort.
-## PARAMETERS
+## Parameters
### -Bottom
property. This process continues until there are no more specified properties or
objects. The **Property** parameter's value can be a calculated property. To create a calculated property,
-use a hash table.
+use a scriptblock or a hashtable.
Valid keys for a hash table are as follows:
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
-## INPUTS
+## Inputs
### System.Management.Automation.PSObject You can pipe the objects to be sorted to `Sort-Object`.
-## OUTPUTS
+## Outputs
### System.Management.Automation.PSObject `Sort-Object` returns the sorted objects.
-## NOTES
+## Notes
The `Sort-Object` cmdlet sorts objects based on properties specified in the command or the default sort properties for the object type. Default sort properties are defined using the `PropertySet`
see [ServiceControllerStatus](/dotnet/api/system.serviceprocess.servicecontrolle
The performance of the sorting algorithm is slower when doing a stable sort.
-## RELATED LINKS
+## Related links
[about_Calculated_Properties](../Microsoft.PowerShell.Core/About/about_Calculated_Properties.md)
samples Managing Services https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/samples/Managing-Services.md
description: PowerShell provides several cmdlets that help manage services on lo
There are eight core Service cmdlets, designed for a wide range of service tasks . We will look only at listing and changing running state for services, but you can get a list of Service cmdlets
-by using `Get-Help \*-Service`, and you can find information about each Service cmdlet by using
+by using `Get-Help *-Service`, and you can find information about each Service cmdlet by using
`Get-Help <Cmdlet-Name>`, such as `Get-Help New-Service`. ## Getting Services
samples Manipulating Items Directly https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/samples/Manipulating-Items-Directly.md
--- Previously updated : 06/05/2017 Last updated : 07/28/2021 keywords: powershell,cmdlet Title: Manipulating Items Directly description: PowerShell provides several cmdlets that help manage items on local and remote computers. Items are objects exposed by PowerShell providers like the file system, registry, certificates, and others.
when you enter its commands. For example, if you try to remove the `New.Director
will be prompted to confirm the command, because the folder contains files: ```powershell
-Remove-Item C:\New.Directory
+Remove-Item C:\temp\New.Directory
``` ```Output
samples Performing Networking Tasks https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/samples/Performing-Networking-Tasks.md
--- Previously updated : 12/23/2019
-keywords: powershell,cmdlet
Title: Performing Networking Tasks description: This article shows how to use WMI classes in PowerShell to manage network configuration setting in Windows. Last updated : 07/28/2021
+ Title: Performing Networking Tasks
--- # Performing Networking Tasks
tasks.
To get all IP addresses in use on the local computer, use the following command: ```powershell
- Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true |
- Select-Object -ExpandProperty IPAddress
+Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true |
+ Select-Object -ExpandProperty IPAddress
```
-The output of this command differs from most property lists, because values are enclosed in braces:
+Since the **IPAddress** property of a **Win32_NetworkAdapterConfiguration** object is an array, you
+must use the **ExpandProperty** parameter of `Select-Object` to see the entire list of addresses.
```Output 10.0.0.1
fe80::60ea:29a7:a233:7cb7
2601:600:a27f:a470::2ec1 ```
-To understand why the braces appear, use the `Get-Member` cmdlet to examine the **IPAddress**
-property:
+Using the `Get-Member` cmdlet, you can see that the **IPAddress** property is an array:
```powershell
- Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true |
- Get-Member -Name IPAddress
+Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true |
+ Get-Member -Name IPAddress
``` ```Output TypeName: Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_NetworkAdapterConfiguration+ Name MemberType Definition ---- ---------- ---------- IPAddress Property string[] IPAddress {get;}
In modern TCP/IP networks you are probably not interested in IPX or WINS propert
```powershell Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true |
- Select-Object -ExcludeProperty IPX*,WINS*
+ Select-Object -ExcludeProperty IPX*,WINS*
``` This command returns detailed information about DHCP, DNS, routing, and other minor IP configuration
You can use an array to ping multiple computers with a single command. Because t
one address, use the `ForEach-Object` to ping each address separately: ```powershell
-'127.0.0.1','localhost','research.microsoft.com' |
+'127.0.0.1','localhost','bing.com' |
ForEach-Object -Process { Get-CimInstance -Class Win32_PingStatus -Filter ("Address='$_'") | Select-Object -Property Address,ResponseTime,StatusCode
network that uses network number 192.168.1.0 and a standard Class C subnet mask
Only addresses in the range of 192.168.1.1 through 192.168.1.254 are legitimate local addresses (0 is always reserved for the network number and 255 is a subnet broadcast address).
-To represent an array of the numbers from 1 through 254 in PowerShell, use the statement **1..254.**
-A complete subnet ping can be performed by generating the array and then adding the values onto a
-partial address in the ping statement:
+To represent an array of the numbers from 1 through 254 in PowerShell, use the expression `1..254`.
+A complete subnet ping can be performed by adding each value in the range to a partial address in
+the ping statement:
```powershell 1..254| ForEach-Object -Process {
- Get-CimInstance -Class Win32_PingStatus -Filter ("Address='192.168.1.$_ '") } |
+ Get-CimInstance -Class Win32_PingStatus -Filter ("Address='192.168.1.$_'") } |
Select-Object -Property Address,ResponseTime,StatusCode ```
Get-CimInstance -Class Win32_NetworkAdapter -ComputerName .
## Assigning the DNS Domain for a Network Adapter To assign the DNS domain for automatic name resolution, use the **SetDNSDomain** method of the
-**Win32_NetworkAdapterConfiguration**. 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:
+**Win32_NetworkAdapterConfiguration**. The **Query** parameter of `Invoke-CimMethod` takes a WQL
+query string. The cmdlet calls the method specified on each instance returned by the query.
```powershell
-Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true |
- ForEach-Object -Process { $_.SetDNSDomain('fabrikam.com') }
+$wql = 'SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True'
+$args = @{ DnsDomain = 'fabrikam.com'}
+Invoke-CimMethod -MethodName SetDNSDomain -Arguments $args -Query $wql
```
-The filtering statement `IPEnabled=$true` is necessary, because even on a network that uses only
-TCP/IP, several of the network adapter configurations on a computer are not true TCP/IP adapters;
-they are general software elements supporting RAS, PPTP, QoS, and other services for all adapters
-and thus do not have an address of their own.
-
-You can filter the command by using the `Where-Object` cmdlet, instead of using the
-`Get-CimInstance` filter.
-
-```powershell
-Get-CimInstance -Class Win32_NetworkAdapterConfiguration |
- Where-Object {$_.IPEnabled} |
- ForEach-Object -Process {$_.SetDNSDomain('fabrikam.com')}
-```
+Filtering on `IPEnabled=True` is necessary, because even on a network that uses only TCP/IP, several
+of the network adapter configurations on a computer are not true TCP/IP adapters. They are general
+software elements supporting RAS, VPN, QoS, and other services for all adapters and thus do not have
+an address of their own.
## 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.
+configuration does. There are several distinct actions you can perform using WMI, and we will step
+through a few of the common ones.
### Determining DHCP-Enabled Adapters
Because DHCP-related properties for an adapter generally begin with `DHCP`, you
parameter of `Format-Table` to display only those properties: ```powershell
-Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=$true" |
+Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=$true and DHCPEnabled=$true" |
Format-Table -Property DHCP* ```
Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=$t
To enable DHCP on all adapters, use the following command: ```powershell
-Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=$true |
- ForEach-Object -Process {$_.EnableDHCP()}
+$wql = 'SELECT * from Win32_NetworkAdapterConfiguration WHERE IPEnabled=True and DHCPEnabled=False'
+Invoke-CimMethod -MethodName ReleaseDHCPLease -Query $wql
```
-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.
+Using the filter statement `IPEnabled=True and DHCPEnabled=False` avoids enabling DHCP where it's
+already enabled.
### 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:
+Instances of 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:
```powershell
-Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=$true and DHCPEnabled=$true" |
- Where-Object {$_.DHCPServer -contains '192.168.1.254'} |
- ForEach-Object -Process {$_.ReleaseDHCPLease()}
+$wql = 'SELECT * from Win32_NetworkAdapterConfiguration WHERE DHCPServer="192.168.1.1"'
+Invoke-CimMethod -MethodName ReleaseDHCPLease -Query $wql
```
-The only change for renewing a DHCP lease is to use the **RenewDHCPLease** method instead of the
-**ReleaseDHCPLease** method:
+The only change for renewing a DHCP lease is to use the `RenewDHCPLease` method instead of the
+`ReleaseDHCPLease` method:
```powershell
-Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=$true and DHCPEnabled=$true" |
- Where-Object {$_.DHCPServer -contains '192.168.1.254'} |
- ForEach-Object -Process {$_.ReleaseDHCPLease()}
+$wql = 'SELECT * from Win32_NetworkAdapterConfiguration WHERE DHCPServer="192.168.1.1"'
+Invoke-CimMethod -MethodName RenewDHCPLease -Query $wql
``` > [!NOTE]
Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=$tru
### 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**.
+**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.-
-You can get a reference to a WMI class, instead of class instances, by listing all WMI classes and
-then selecting only the desired class by name. For example, the following command returns the
-**Win32_NetworkAdapterConfiguration** class:
-
-```powershell
-Get-CimInstance -List | Where-Object {$_.Name -eq 'Win32_NetworkAdapterConfiguration'}
-```
-
-You can treat the entire command as the class and then invoke the **ReleaseDHCPAdapterLease** method
-on it. In the following command, the parentheses surrounding the `Get-CimInstance` and
-`Where-Object` pipeline elements direct PowerShell to evaluate them first:
+The `Invoke-CimMethod` cmdlet can call the methods of a class.
```powershell
-(Get-CimInstance -List |
- Where-Object {$_.Name -eq 'Win32_NetworkAdapterConfiguration'}).ReleaseDHCPLeaseAll()
+Invoke-CimMethod -ClassName Win32_NetworkAdapterConfiguration -MethodName ReleaseDHCPLeaseAll
``` You can use the same command format to invoke the **RenewDHCPLeaseAll** method: ```powershell
-(Get-CimInstance -List |
- Where-Object {$_.Name -eq 'Win32_NetworkAdapterConfiguration'}).RenewDHCPLeaseAll()
+Invoke-CimMethod -ClassName Win32_NetworkAdapterConfiguration -MethodName RenewDHCPLeaseAll
``` ## Creating a Network Share
-To create a network share, use the **Create** method of **Win32_Share**:
+To create a network share, use the `Create` method of **Win32_Share**:
```powershell
-(Get-CimInstance -List |
- Where-Object {$_.Name -eq 'Win32_Share'}).Create(
- 'C:\temp','TempShare',0,25,'test share of the temp folder'
- )
+Invoke-CimMethod -ClassName Win32_Share -MethodName Create -Arguments @{
+ Path = 'C:\temp'
+ Name = 'TempShare'
+ Type = [uint32]0 #Disk Drive
+ MaximumAllowed = [uint32]25
+ Description = 'test share of the temp folder'
+}
```
-You can also create the share by using `net share` in PowerShell on Windows:
+This is equivalent to the following `net share` command on Windows:
```powershell net share tempshare=c:\temp /users:25 /remark:"test share of the temp folder" ```
-## 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**:
+To call a method of a WMI class that takes parameters you must know what parameters are available
+and the types of those parameters. For example, you can list the methods of the **Win32_Class** with
+the following commands:
```powershell
-(Get-CimInstance -Class Win32_Share -Filter "Name='TempShare'").Delete()
+(Get-CimClass -ClassName Win32_Share).CimClassMethods
+```
+
+```Output
+Name ReturnType Parameters Qualifiers
+---- ---------- ---------- ----------
+Create UInt32 {Access, Description, MaximumAllowed, Name…} {Constructor, Implemented, MappingStrings, Stati…
+SetShareInfo UInt32 {Access, Description, MaximumAllowed} {Implemented, MappingStrings}
+GetAccessMask UInt32 {} {Implemented, MappingStrings}
+Delete UInt32 {} {Destructor, Implemented, MappingStrings}
```
-In Windows, `net share` works as well:
+Use the following command to list the parameters of the `Create` method.
```powershell
-net share tempshare /delete
+(Get-CimClass -ClassName Win32_Share).CimClassMethods['Create'].Parameters
``` ```Output
-tempshare was deleted successfully.
+Name CimType Qualifiers ReferenceClassName
+---- ------- ---------- ------------------
+Access Instance {EmbeddedInstance, ID, In, MappingStrings…}
+Description String {ID, In, MappingStrings, Optional}
+MaximumAllowed UInt32 {ID, In, MappingStrings, Optional}
+Name String {ID, In, MappingStrings}
+Password String {ID, In, MappingStrings, Optional}
+Path String {ID, In, MappingStrings}
+Type UInt32 {ID, In, MappingStrings}
+```
+
+You can also read the documentation for
+[Create](/windows/win32/cimwin32prov/create-method-in-class-win32-share) method of the
+**Win32_Share** class.
+
+## 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 instance to be removed, rather than the
+**Win32_Share** class. The following example deletes the share **TempShare**:
+
+```powershell
+$wql = 'SELECT * from Win32_Share WHERE Name="TempShare"'
+Invoke-CimMethod -MethodName Delete -Query $wql
``` ## Connecting a Windows Accessible Network Drive
-The `New-PSDrive` cmdlets creates a PowerShell drive, but drives created this way are available only
-to 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:`,
+The `New-PSDrive` cmdlet can create a PowerShell drive that is mapped to a network share.
```powershell
-(New-Object -ComObject WScript.Network).MapNetworkDrive('B:', '\\FPS01\users')
+New-PSDrive -Name "X" -PSProvider "FileSystem" -Root "\\Server01\Public"
```
-On Windows, the `net use` command works as well:
+However, drives created this way are only available to PowerShell session where they are created. To
+map a drive that is available outside of PowerShell (or to other PowerShell sessions), you must use
+the **Persist** parameter.
```powershell
-net use B: \\FPS01\users
+New-PSDrive -Persist -Name "X" -PSProvider "FileSystem" -Root "\\Server01\Public"
```
-Drives mapped with either **WScript.Network** or `net use` are immediately available to PowerShell.
+> [!NOTE]
+> Persistently mapped drives may not be available when running in an elevated context. This is the
+> default behavior of Windows UAC. For more information, see the following article:
+>
+>- [Mapped drives are not available from an elevated prompt when UAC is configured to Prompt for credentials](/troubleshoot/windows-client/networking/mapped-drives-not-available-from-elevated-command)
samples Redirecting Data With Out Cmdlets https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/samples/Redirecting-Data-with-Out---Cmdlets.md
--- Previously updated : 06/05/2017 Last updated : 07/28/2021 keywords: powershell,cmdlet Title: Redirecting Data with Out Cmdlets description: This article shows how to use the cmdlets that manage output in PowerShell. --- # Redirecting Data with Out-* Cmdlets
-Windows PowerShell provides several cmdlets that let you control data output directly. These cmdlets share two important characteristics.
+Windows PowerShell provides several cmdlets that let you control data output directly. These cmdlets
+share two important characteristics.
-First, they generally transform data to some form of text. They do this because they output the data to system components that require text input. This means they need to represent the objects as text. Therefore, the text is formatted as you see it in the Windows PowerShell console window.
+First, they generally transform data to some form of text. They do this because they output the data
+to system components that require text input. This means they need to represent the objects as text.
+Therefore, the text is formatted as you see it in the Windows PowerShell console window.
-Second, these cmdlets use the Windows PowerShell verb **Out** because they send information out from Windows PowerShell to somewhere else. The **Out-Host** cmdlet is no exception: the host window display is outside of Windows PowerShell. This is important because when data is sent out of Windows PowerShell, it is actually removed. You can see this if you try to create a pipeline that pages data to the host window, and then attempt to format it as a list, as shown here:
+Second, these cmdlets use the Windows PowerShell verb **Out** because they send information out from
+Windows PowerShell to somewhere else.
+
+## 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. For example, the following command
+uses `Out-Host` to page the output of the `Get-Command` cmdlet:
+
+```powershell
+Get-Command | Out-Host -Paging
+```
+
+The host window display is outside of Windows PowerShell. This is important because when data is
+sent out of Windows PowerShell, it is actually removed. You can see this if you try to create a
+pipeline that pages data to the host window, and then attempt to format it as a list, as shown here:
```powershell Get-Process | Out-Host -Paging | Format-List ```
-You might expect the command to display pages of process information in list format. Instead, it displays the default tabular list:
+You might expect the command to display pages of process information in list format. Instead, it
+displays the default tabular list:
```output Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
... ```
-The **Out-Host** cmdlet sends the data directly to the console, so the **Format-List** command never receives anything to format.
+The `Out-Host` cmdlet sends the data directly to the console, so the `Format-List` command never
+receives anything to format.
-The correct way to structure this command is to put the **Out-Host** cmdlet at the end of the pipeline as shown below. This causes the process data to be formatted in a list before being paged and displayed.
+The correct way to structure this command is to put the `Out-Host` cmdlet at the end of the
+pipeline as shown below. This causes the process data to be formatted in a list before being paged
+and displayed.
+```powershell
+Get-Process | Format-List | Out-Host -Paging
```
-PS> Get-Process | Format-List | Out-Host -Paging
+```Output
Id : 2888 Handles : 101 CPU : 0.046875
Name : explorer
... ```
-This applies to all of the **Out** cmdlets. An **Out** cmdlet should always appear at the end of the pipeline.
+This applies to all of the **Out** cmdlets. An **Out** cmdlet should always appear at the end of the
+pipeline.
> [!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)
-
-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:
-
-```powershell
-Get-Command | Out-Host -Paging
-```
-
-You can also use the **more** function to page data. In Windows PowerShell, **more** is a function that calls **Out-Host -Paging**. The following command demonstrates using the **more** function to page the output of Get-Command:
-
-```powershell
-Get-Command | more
-```
-
-If you include one or more filenames as arguments to the more function, the function will read the specified files and page their contents to the host:
-
-```
-PS> more c:\boot.ini
-[boot loader]
-timeout=5
-default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
-[operating systems]
-...
-```
+> All the **Out** cmdlets render output as text, using the formatting in effect for the console
+> window, including line length limits.
## 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:
+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:
```powershell Get-Command | Out-Null ```
-The **Out-Null** cmdlet does not discard error output. For example, if you enter the following command, a message is displayed informing you that Windows PowerShell does not recognize 'Is-NotACommand':
+The `Out-Null` cmdlet does not discard error output. For example, if you enter the following
+command, a message is displayed informing you that Windows PowerShell does not recognize
+'Is-NotACommand':
``` PS> Get-Command Is-NotACommand | Out-Null
-Get-Command : 'Is-NotACommand' is not recognized as a cmdlet, function, operabl
-e program, or script file.
+Get-Command : 'Is-NotACommand' is not recognized as a cmdlet, function, operable program, or script file.
At line:1 char:12 + Get-Command <<<< Is-NotACommand | Out-Null ``` ## 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:
+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:
```powershell Get-Command Get-Command | Out-Printer -Name 'Microsoft Office Document Image Writer'
Get-Command Get-Command | Out-Printer -Name 'Microsoft Office Document Image Wri
## 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**:
+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`:
```powershell Get-Process | Out-File -FilePath C:\temp\processlist.txt ```
-The results of using the **Out-File** cmdlet may not be what you expect if you are used to traditional output redirection. To understand its behavior, you must be aware of the context in which the **Out-File** cmdlet operates.
+The results of using the `Out-File` cmdlet may not be what you expect if you are used to
+traditional output redirection. To understand its behavior, you must be aware of the context in
+which the `Out-File` cmdlet operates.
-By default, the **Out-File** cmdlet creates a Unicode file. This is the best default in the long run, but it means that tools that expect ASCII files will not work correctly with the default output format. You can change the default output format to ASCII by using the **Encoding** parameter:
+By default, the `Out-File` cmdlet creates a Unicode file. This is the best default in the long
+run, but it means that tools that expect ASCII files will not work correctly with the default output
+format. You can change the default output format to ASCII by using the **Encoding** parameter:
```powershell Get-Process | Out-File -FilePath C:\temp\processlist.txt -Encoding ASCII ```
-**Out-file** formats file contents to look like console output. This causes the output to be truncated just as it is in a console window in most circumstances. For example, if you run the following command:
+`Out-file` formats file contents to look like console output. This causes the output to be
+truncated just as it is in a console window in most circumstances. For example, if you run the
+following command:
```powershell Get-Command | Out-File -FilePath c:\temp\output.txt
Cmdlet Add-History Add-History [[-InputObject] ...
... ```
-To get output that does not force line wraps to match the screen width, you can use the **Width** parameter to specify line width. Because **Width** is a 32-bit integer parameter, the maximum value it can have is 2147483647. Type the following to set the line width to this maximum value:
+To get output that does not force line wraps to match the screen width, you can use the **Width**
+parameter to specify line width. Because **Width** is a 32-bit integer parameter, the maximum value
+it can have is 2147483647. Type the following to set the line width to this maximum value:
```powershell Get-Command | Out-File -FilePath c:\temp\output.txt -Width 2147483647 ```
-The **Out-File** cmdlet is most useful when you want to save output as it would have displayed on the console. For finer control over output format, you need more advanced tools. We will look at those in the next chapter, along with some details about object manipulation.
+The `Out-File` cmdlet is most useful when you want to save output as it would have displayed on
+the console. For finer control over output format, you need more advanced tools. We will look at
+those in the next chapter, along with some details about object manipulation.
samples Working With Software Installations https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/samples/Working-with-Software-Installations.md
--- Previously updated : 12/23/2019 Last updated : 07/28/2021 keywords: powershell,cmdlet Title: Working with Software Installations description: This article shows how to use WMI to manage software installed in Windows.
command:
$UninstallableApplications | ForEach-Object -Process { $_.GetValue('DisplayName') } ```
-There is no guarantee that these values are unique. In the following example, two installed items
-appear as "Windows Media Encoder 9 Series":
-
-```powershell
-$UninstallableApplications | Where-Object -FilterScript {
- $_.GetValue("DisplayName") -eq "Microsoft Silverlight"
-}
-```
-
-```Output
- Hive: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
-
-Name Property
-{89F4137D-6C26-4A84-BDB8-2E5A4 AuthorizedCDFPrefix :
-BB71E00} Comments :
- Contact :
- DisplayVersion : 5.1.50918.0
- HelpLink : https://go.microsoft.com/fwlink/?LinkID=91955
- HelpTelephone :
- InstallDate : 20190115
- InstallLocation : C:\Program Files\Microsoft Silverlight\
- InstallSource : c:\ef64c54526db9c34cd477c103e68a254\
- ModifyPath : MsiExec.exe /X{89F4137D-6C26-4A84-BDB8-2E5A4BB71E00}
- NoModify : 1
- NoRepair : 1
- Publisher : Microsoft Corporation
- Readme :
- Size :
- EstimatedSize : 236432
- UninstallString : MsiExec.exe /X{89F4137D-6C26-4A84-BDB8-2E5A4BB71E00}
- URLInfoAbout :
- URLUpdateInfo :
- VersionMajor : 5
- VersionMinor : 1
- WindowsInstaller : 1
- Version : 84002534
- Language : 1033
- DisplayName : Microsoft Silverlight
- sEstimatedSize2 : 79214
-```
+> [!NOTE]
+> There is no guarantee that the **DisplayName** values are unique.
## Installing Applications