diff --git a/reference/5.1/CimCmdlets/Set-CimInstance.md b/reference/5.1/CimCmdlets/Set-CimInstance.md index de58c8f0fb70..b819def2ee4e 100644 --- a/reference/5.1/CimCmdlets/Set-CimInstance.md +++ b/reference/5.1/CimCmdlets/Set-CimInstance.md @@ -234,9 +234,9 @@ Accept wildcard characters: False ### -Namespace -Specifies the namespace for the CIM operation. The default namespace is root/cimv2. You can use tab -completion to browse the list of namespaces, because PowerShell gets a list of namespaces from the -local WMI server to provide the list of namespaces. +Specifies the namespace for the CIM operation. The default namespace is **root/CIMV2**. You can use +tab completion to browse the list of namespaces, because PowerShell gets a list of namespaces from +the local WMI server to provide the list of namespaces. ```yaml Type: System.String @@ -360,11 +360,11 @@ A URI consists of a prefix and a path to a resource. For example: By default, if you do not specify this parameter, the DMTF standard resource URI `http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/` is used and the class name is appended to it. -ResourceURI can only be used with CIM sessions created using the WSMan protocol, or when specifying -the ComputerName parameter, which creates a CIM session using WSMan. If you specify this parameter -without specifying the ComputerName parameter, or if you specify a CIM session created using DCOM -protocol, you will get an error, because the DCOM protocol does not support the ResourceURI -parameter. +**ResourceUri** can only be used with CIM sessions created using the WSMan protocol, or when +specifying the **ComputerName** parameter, which creates a CIM session using WSMan. If you specify +this parameter without specifying the **ComputerName** parameter, or if you specify a CIM session +created using DCOM protocol, you will get an error, because the DCOM protocol does not support the +**ResourceUri** parameter. If both the **ResourceUri** parameter and the **Filter** parameter are specified, the **Filter** parameter is ignored. diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/About.md b/reference/5.1/Microsoft.PowerShell.Core/About/About.md index b00906ae222e..0cd214343b49 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/About.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/About.md @@ -150,7 +150,7 @@ Provides a brief introduction to the PowerShell Desired State Configuration ### [about_Do](about_Do.md) -Runs a statement list one or more times, subject to a `While` or `Until` +Runs a statement list one or more times, subject to a `while` or `until` condition. ### [about_Enum](about_Enum.md) @@ -267,8 +267,8 @@ expression in the background without interacting with the current session. ### [about_Join](about_Join.md) -Describes how the join operator (-join) combines multiple strings into a single -string. +Describes how the join operator (`-join`) combines multiple strings into a +single string. ### [about_Language_Keywords](about_Language_Keywords.md) @@ -377,7 +377,7 @@ command-line parameters and describes the syntax. ### [about_PowerShell_Ise_exe](about_PowerShell_Ise_exe.md) -Explains how to use the PowerShell_Ise.exe command-line tool. +Explains how to use the `powershell_ise.exe` command-line tool. ### [about_Preference_Variables](about_Preference_Variables.md) @@ -389,8 +389,8 @@ Describes how to create and use a PowerShell profile. ### [about_Prompts](about_Prompts.md) -Describes the `Prompt` function and demonstrates how to create a custom -`Prompt` function. +Describes the `prompt` function and demonstrates how to create a custom +`prompt` function. ### [about_Properties](about_Properties.md) @@ -417,7 +417,7 @@ The automatic variable that contains the current object in the pipeline object. ### [about_PSModulePath](about_PSModulePath.md) -This article the purpose and usage of the `$env:PSModulePath` environment +This article the purpose and usage of the `$Env:PSModulePath` environment variable. ### [about_PSSession_Details](about_PSSession_Details.md) diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md index 2549cd0ecdd9..aa1ae33a966a 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md @@ -3,7 +3,7 @@ description: Describes the features of PowerShell that use ANSI escape sequences Locale: en-US ms.date: 03/01/2023 schema: 2.0.0 -title: about_ANSI_terminals +title: about_ANSI_Terminals --- # about_ANSI_Terminals diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Alias_Provider.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Alias_Provider.md index 86d20bd307af..492611cd599d 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Alias_Provider.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Alias_Provider.md @@ -149,7 +149,7 @@ current location is in the `Alias:` drive, the `-Path` parameter is not needed. This command also uses the `-Options` dynamic parameter to set the **AllScope** option on the alias. The `-Options` parameter is available in the `New-Item` cmdlet only when you are in the `Alias:` drive. The dot (`.`) indicates the -current directory, which is the alias drive. +current directory, which is the `Alias:` drive. ``` PS Alias:\> New-Item -Path . -Name serv -Value Get-Service -Options "AllScope" @@ -161,7 +161,7 @@ You can create an alias for any item that invokes a command. This command creates the `np` alias for `Notepad.exe`. ```powershell -New-Item -Path Alias:np -Value c:\windows\notepad.exe +New-Item -Path Alias:np -Value C:\windows\notepad.exe ``` ### Create an alias to a new function @@ -177,7 +177,7 @@ When the command is complete, you can use either `CD32` or `go` to invoke the function. ```powershell -function CD32 {Set-Location -Path c:\windows\system32} +function CD32 {Set-Location -Path C:\windows\system32} Set-Item -Path Alias:go -Value CD32 ``` @@ -313,7 +313,7 @@ Get-Help Get-ChildItem ``` ```powershell -Get-Help Get-ChildItem -Path alias: +Get-Help Get-ChildItem -Path Alias: ``` ## See also diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md index 76d64b67bb82..919d5b3b4297 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md @@ -227,7 +227,7 @@ following example, the negative value can't be cast to an unsigned integer, and the unsigned integer is too large to be cast to `Int32`: ```powershell -([int32]::minvalue + [uint32]::maxvalue).GetType().FullName +([int32]::MinValue + [uint32]::MaxValue).GetType().FullName ``` ```Output @@ -241,10 +241,10 @@ The `System.Decimal` type is an exception. If either operand has the **Decimal** value is an error. ```powershell -PS> [Decimal]::maxvalue +PS> [decimal]::MaxValue 79228162514264337593543950335 -PS> [Decimal]::maxvalue + 1 +PS> [decimal]::MaxValue + 1 RuntimeException: Value was either too large or too small for a Decimal. ``` @@ -454,12 +454,12 @@ InvalidOperation: A hash table can only be added to another hash table. Although the addition operators are very useful, use the assignment operators to add elements to hash tables and arrays. For more information see -[about_assignment_operators](about_Assignment_Operators.md). The following +[about_Assignment_Operators](about_Assignment_Operators.md). The following examples use the `+=` assignment operator to add items to an array: ```powershell $array = @() -(0..2).foreach{ $array += $_ } +(0..2).ForEach{ $array += $_ } $array ``` @@ -497,7 +497,7 @@ The following examples show how to use the arithmetic operators in expressions with PowerShell commands: ```powershell -(Get-Date) + (New-TimeSpan -day 1) +(Get-Date) + (New-TimeSpan -Day 1) ``` The parenthesis operator forces the evaluation of the `Get-Date` cmdlet and the @@ -505,7 +505,7 @@ evaluation of the `New-TimeSpan -Day 1` cmdlet expression, in that order. Both results are then added using the `+` operator. ```powershell -Get-Process | Where-Object { ($_.ws * 2) -gt 50mb } +Get-Process | Where-Object { ($_.WS * 2) -gt 50mb } ``` ```Output @@ -519,7 +519,7 @@ Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName 967 30 58804 59496 416 930.97 2508 WINWORD ``` -In the above expression, each process working space (`$_.ws`) is multiplied by +In the above expression, each process working space (`$_.WS`) is multiplied by `2`; and, the result, compared against `50mb` to see if it's greater than that. ## Bitwise operators @@ -540,7 +540,7 @@ PowerShell supports the following bitwise operators. | `-band` | Bitwise AND | `10 -band 3` | 2 | | `-bor` | Bitwise OR (inclusive) | `10 -bor 3` | 11 | | `-bxor` | Bitwise OR (exclusive) | `10 -bxor 3` | 9 | -| `-bnot` | Bitwise NOT | `-bNot 10` | -11 | +| `-bnot` | Bitwise NOT | `-bnot 10` | -11 | | `-shl` | Shift-left | `102 -shl 2` | 408 | | `-shr` | Shift-right | `102 -shr 1` | 51 | @@ -587,7 +587,7 @@ For example, the binary complement of 0 is -1, the maximum unsigned integer (0xFFFFFFFF), and the binary complement of -1 is 0. ```powershell --bNot 10 +-bnot 10 ``` ```Output diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Arrays.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Arrays.md index 851033378976..9ecfe8fa992e 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Arrays.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Arrays.md @@ -305,7 +305,7 @@ value in an array, type: ```powershell $a = 0..9 -for ($i = 0; $i -le ($a.length - 1); $i += 2) { +for ($i = 0; $i -le ($a.Length - 1); $i += 2) { $a[$i] } ``` @@ -346,11 +346,11 @@ In PowerShell, arrays have three properties that indicate the number of items contained in the array. - **Count** - This property is the most commonly used property to determine the - number of items in any collection, not just an array. It's an `[Int32]` type + number of items in any collection, not just an array. It's an `[int32]` type value. In Windows PowerShell 5.1 (and older) **Count** alias property for **Length**. -- **Length** - This property is an `[Int32]` type value. This contains the same +- **Length** - This property is an `[int32]` type value. This contains the same value as **Count**. > [!NOTE] @@ -359,7 +359,7 @@ contained in the array. > string is the number of characters in the string. But the **Count** > property is always `1`. -- **Longlength** - This property is an `[Int64]` type value. Use this property +- **LongLength** - This property is an `[int64]` type value. Use this property for arrays containing more than 2,147,483,647 elements. ```powershell @@ -408,8 +408,8 @@ Multidimensional arrays are stored in [row-major order][14]. The following example shows how to create a truly multidimensional array. ```powershell -[string[,]]$rank2 = [string[,]]::New(3,2) -$rank2.rank +[string[,]]$rank2 = [string[,]]::new(3,2) +$rank2.Rank $rank2.Length $rank2[0,0] = 'a' $rank2[0,1] = 'b' @@ -487,7 +487,7 @@ True In this example, `$intA` is explicitly typed to contain integers. ```powershell -[Int[]] $intA = 1, 2, 3 +[int[]] $intA = 1, 2, 3 $intA.Clear() $intA ``` @@ -552,7 +552,7 @@ For more information about the behavior of **ArgumentList**, see The `ForEach()` method can be used to cast the elements to a different type; the following example shows how to convert a list of string dates to -`[DateTime]` type. +`[datetime]` type. ```powershell ("1/1/2017", "2/1/2017", "3/1/2017").ForEach([datetime]) @@ -680,7 +680,7 @@ to return. ```powershell # Get the zip files in the current users profile, sorted by LastAccessTime -$Zips = dir $env:userprofile -Recurse '*.zip' | Sort-Object LastAccessTime +$Zips = dir $Env:USERPROFILE -Recurse '*.zip' | Sort-Object LastAccessTime # Get the least accessed file over 100MB $Zips.Where({$_.Length -gt 100MB}, 'Default', 1) ``` @@ -876,7 +876,7 @@ create the `$t` array with all the elements in the `$a` array except for the value at index position 2, type: ```powershell -$t = $a[0,1 + 3..($a.length - 1)] +$t = $a[0,1 + 3..($a.Length - 1)] ``` To combine two arrays into a single array, use the plus operator (`+`). The @@ -1093,7 +1093,7 @@ LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;} ## See also - [about_For][05] -- [about_ForEach][06] +- [about_Foreach][06] - [about_Hash_Tables][07] - [about_Member-Access_Enumeration][09] - [about_Operators][11] @@ -1106,7 +1106,7 @@ LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;} [03]: about_Assignment_Operators.md [04]: about_Booleans.md [05]: about_For.md -[06]: about_ForEach.md +[06]: about_Foreach.md [07]: about_Hash_Tables.md [08]: about_Intrinsic_Members.md [09]: about_Member-Access_Enumeration.md diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md index 51451fd59a07..ef6fd3636320 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md @@ -82,7 +82,7 @@ pipeline to a variable. For example, the following command sorts the services on the computer and then assigns the sorted services to the `$a` variable: ```powershell -$a = Get-Service | Sort-Object -Property name +$a = Get-Service | Sort-Object -Property Name ``` You can also assign the value created by a statement to a variable, as in the diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md index 0ecc090fcd66..cd4a74bdcb66 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md @@ -204,8 +204,8 @@ non-zero integer. ### `$foreach` -Contains the enumerator (not the resulting values) of a [ForEach][56] loop. The -`$foreach` variable exists only while the `ForEach` loop is running; it's +Contains the enumerator (not the resulting values) of a [foreach][56] loop. The +`$foreach` variable exists only while the `foreach` loop is running; it's deleted after the loop is completed. Enumerators contain properties and methods you can use to retrieve loop values @@ -215,18 +215,18 @@ and change the current loop iteration. For more information, see ### `$HOME` Contains the full path of the user's home directory. This variable uses the -value of the `"$env:USERPROFILE"` Windows environment variable, typically +value of the `"$Env:USERPROFILE"` Windows environment variable, typically `C:\Users\`. > [!IMPORTANT] > Windows can redirect the location of the user's profile. This means that -> `$HOME` may not have the same value as `"$env:HOMEDRIVE$env:HOMEPATH"`. +> `$HOME` may not have the same value as `"$Env:HOMEDRIVE$Env:HOMEPATH"`. ### `$Host` Contains an object that represents the current host application for PowerShell. You can use this variable to represent the current host in commands or to -display or change the properties of the host, such as `$Host.version` or +display or change the properties of the host, such as `$Host.Version` or `$Host.CurrentCulture`, or `$Host.UI.RawUI.BackGroundColor = "Red"`. ### $input @@ -456,7 +456,7 @@ Test-Path $PROFILE Or, you can use it in a command to create a profile: ```powershell -New-Item -ItemType file -Path $PROFILE -Force +New-Item -ItemType File -Path $PROFILE -Force ``` You can use it in a command to open the profile in **notepad.exe**: @@ -550,7 +550,7 @@ available for use in module manifest files, whereas `$PSVersionTable` isn't. ### `$PSHOME` Contains the full path of the installation directory for PowerShell, typically, -`$env:windir\System32\PowerShell\v1.0` in Windows systems. You can use this +`$Env:windir\System32\PowerShell\v1.0` in Windows systems. You can use this variable in the paths of PowerShell files. For example, the following command searches the conceptual Help topics for the word **Help**: @@ -639,8 +639,8 @@ Contains a stack trace for the most recent error. ### `$switch` -Contains the enumerator not the resulting values of a `Switch` statement. The -`$switch` variable exists only while the `Switch` statement is running; it's +Contains the enumerator not the resulting values of a `switch` statement. The +`$switch` variable exists only while the `switch` statement is running; it's deleted when the `switch` statement completes execution. For more information, see [about_Switch][71]. @@ -1093,7 +1093,7 @@ Default (Current): End [53]: about_CommonParameters.md [54]: about_comparison_operators.md [55]: about_Continue.md -[56]: about_ForEach.md +[56]: about_Foreach.md [57]: about_Functions_Advanced_Methods.md [58]: about_Functions_Advanced_Parameters.md [59]: about_Functions_Advanced.md diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Booleans.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Booleans.md index 7f4728630e38..417dbcd6848d 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Booleans.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Booleans.md @@ -90,7 +90,7 @@ Examples: # Empty collections PS> [bool]@() False -PS> [bool](Get-ChildItem | Where-Object Name -eq 'Non-existent-File.txt') +PS> [bool](Get-ChildItem | Where-Object Name -EQ 'Non-existent-File.txt') False # Single-element collections PS> $a = @(0) diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md index 12c09bba6b32..bba876d06912 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md @@ -33,76 +33,76 @@ The following list itemizes the cmdlets that support calculated properties and the key-value pairs that each cmdlet supports. - `Compare-Object` - - `expression` + - `Expression` - `ConvertTo-Html` - - `name`/`label` - optional (added in PowerShell 6.x) - - `expression` - - `width` - optional - - `alignment` - optional + - `Name`/`Label` - optional (added in PowerShell 6.x) + - `Expression` + - `Width` - optional + - `Alignment` - optional - `Format-Custom` - - `expression` - - `depth` - optional + - `Expression` + - `Depth` - optional - `Format-List` - - `name`/`label` - optional - - `expression` - - `formatstring` - optional + - `Name`/`Label` - optional + - `Expression` + - `FormatString` - optional This same set of key-value pairs also apply to calculated property values passed to the **GroupBy** parameter for all `Format-*` cmdlets. - `Format-Table` - - `name`/`label` - optional - - `expression` - - `formatstring` - optional - - `width` - optional - - `alignment` - optional + - `Name`/`Label` - optional + - `Expression` + - `FormatString` - optional + - `Width` - optional + - `Alignment` - optional - `Format-Wide` - - `expression` - - `formatstring` - optional + - `Expression` + - `FormatString` - optional - `Group-Object` - - `expression` + - `Expression` - `Measure-Object` - Only supports a script block for the expression, not a hashtable. - Not supported in PowerShell 5.1 and older. - `Select-Object` - - `name`/`label` - optional - - `expression` + - `Name`/`Label` - optional + - `Expression` - `Sort-Object` - - `expression` - - `ascending`/`descending` - optional + - `Expression` + - `Ascending`/`Descending` - optional > [!NOTE] -> The value of the `expression` can be a script block instead of a +> The value of the `Expression` can be a script block instead of a > hashtable. For more information, see the [Notes][02] section. ## Hashtable key definitions -- `name`/`label` - Specifies the name of the property being created. You can - use `name` or its alias, `label`, interchangeably. -- `expression` - A string or script block used to calculate the value of the - new property. If the `expression` is a string, the value is interpreted as a +- `Name`/`Label` - Specifies the name of the property being created. You can + use `Name` or its alias, `Label`, interchangeably. +- `Expression` - A string or script block used to calculate the value of the + new property. If the `Expression` is a string, the value is interpreted as a property name on the input object. This is a shorter option than - `expression = { $_. }`. -- `alignment` - Used by cmdlets that produce tabular output to define how the - values are displayed in a column. The value must be `'left'`, `'center'`, or - `'right'`. -- `formatstring` - Specifies a format string that defines how the value is + `Expression = { $_. }`. +- `Alignment` - Used by cmdlets that produce tabular output to define how the + values are displayed in a column. The value must be `'Left'`, `'Center'`, or + `'Right'`. +- `FormatString` - Specifies a format string that defines how the value is formatted for output. For more information about format strings, see [Format types in .NET][01]. -- `width` - Specifies the maximum width column in a table when the value is +- `Width` - Specifies the maximum width column in a table when the value is displayed. The value must be greater than `0`. -- `depth` - The **Depth** parameter of `Format-Custom` specifies the depth of - expansion for all properties. The `depth` key allows you to specify the +- `Depth` - The **Depth** parameter of `Format-Custom` specifies the depth of + expansion for all properties. The `Depth` key allows you to specify the depth of expansion per property. -- `ascending` / `descending` - Allows you to specify the order of sorting for +- `Ascending` / `Descending` - Allows you to specify the order of sorting for one or more properties. These are boolean values. You don't need to spell out the hashtable keys as long as the specified name @@ -119,7 +119,7 @@ directly, the values are compared to the result of the arithmetic operation (modulus of 2). ```powershell -Compare-Object @{p=1} @{p=2} -property @{ Expression = { $_.p % 2 } } +Compare-Object @{p=1} @{p=2} -Property @{ Expression = { $_.p % 2 } } ``` ```Output @@ -139,8 +139,8 @@ Get-Alias | ConvertTo-Html Name, Definition, @{ - expr={$_.Parameters.Keys.Count} - align='center' + Expr={$_.Parameters.Keys.Count} + Align='Center' } | Out-File .\aliases.htm -Force ``` @@ -154,15 +154,15 @@ the number parameters for each aliased command. The values of `Format-Custom` provides a custom view of an object in a format similar to a class definition. More complex objects can contain members that are deeply nested with complex types. The **Depth** parameter of `Format-Custom` specifies -the depth of expansion for all properties. The `depth` key allows you to +the depth of expansion for all properties. The `Depth` key allows you to specify the depth of expansion per property. -In this example, the `depth` key simplifies the custom output for the +In this example, the `Depth` key simplifies the custom output for the `Get-Date` cmdlet. `Get-Date` returns a **DateTime** object. The **Date** property of this object is also a **DateTime** object, so the object is nested. ```powershell -Get-Date | Format-Custom @{expr={$_.Date};depth=1},TimeOfDay +Get-Date | Format-Custom @{Expr={$_.Date};Depth=1},TimeOfDay ``` ```Output @@ -211,16 +211,16 @@ the output from `Get-ChildItem`. ```powershell Get-ChildItem *.json -File | - Format-List Fullname, + Format-List FullName, @{ - name='Modified' - expression={$_.LastWriteTime} - formatstring='O' + Name='Modified' + Expression={$_.LastWriteTime} + FormatString='O' }, @{ - name='Size' - expression={$_.Length/1KB} - formatstring='N2' + Name='Size' + Expression={$_.Length/1KB} + FormatString='N2' } ``` @@ -245,11 +245,11 @@ classify the files by the content type. ```powershell Get-ChildItem -File | - Sort-Object extension | + Sort-Object Extension | Format-Table Name, Length -GroupBy @{ - name='Type' - expression={ - switch ($_.extension) { + Name='Type' + Expression={ + switch ($_.Extension) { '.md' {'Content'} '' {'Metacontent'} '.ps1' {'Automation'} @@ -311,7 +311,7 @@ value. ```powershell Get-ChildItem -File | - Format-Wide -Property @{e={'{0} ({1:N2}kb)' -f $_.name,($_.length/1kb)}} + Format-Wide -Property @{e={'{0} ({1:N2}kb)' -f $_.Name,($_.Length/1kb)}} ``` ```Output @@ -334,10 +334,10 @@ of files of each content type. ```powershell Get-ChildItem -File | - Sort-Object extension | + Sort-Object Extension | Group-Object -NoElement -Property @{ - expression={ - switch ($_.extension) { + Expression={ + switch ($_.Extension) { '.md' {'Content'} '' {'Metacontent'} '.ps1' {'Automation'} @@ -371,8 +371,8 @@ $aliases = Get-Alias c* | Select-Object Name, Definition, @{ - name='ParameterCount' - expr={$_.Parameters.Keys.Count} + Name='ParameterCount' + Expr={$_.Parameters.Keys.Count} } $aliases | Get-Member $aliases @@ -422,7 +422,7 @@ property. This example sorts data from a CSV file in ascending order by ```powershell Import-Csv C:\temp\sales-data.csv | - Sort-Object Date, @{expr={$_.UnitsSold}; desc=$true}, Salesperson | + Sort-Object Date, @{Expr={$_.UnitsSold}; Desc=$true}, Salesperson | Select-Object Date, Salesperson, UnitsSold ``` diff --git a/reference/7.4/CimCmdlets/Set-CimInstance.md b/reference/7.4/CimCmdlets/Set-CimInstance.md index 3b10e826c2ac..38e73f6950dc 100644 --- a/reference/7.4/CimCmdlets/Set-CimInstance.md +++ b/reference/7.4/CimCmdlets/Set-CimInstance.md @@ -236,9 +236,9 @@ Accept wildcard characters: False ### -Namespace -Specifies the namespace for the CIM operation. The default namespace is root/cimv2. You can use tab -completion to browse the list of namespaces, because PowerShell gets a list of namespaces from the -local WMI server to provide the list of namespaces. +Specifies the namespace for the CIM operation. The default namespace is **root/CIMV2**. You can use +tab completion to browse the list of namespaces, because PowerShell gets a list of namespaces from +the local WMI server to provide the list of namespaces. ```yaml Type: System.String @@ -362,11 +362,11 @@ A URI consists of a prefix and a path to a resource. For example: By default, if you do not specify this parameter, the DMTF standard resource URI `http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/` is used and the class name is appended to it. -ResourceURI can only be used with CIM sessions created using the WSMan protocol, or when specifying -the ComputerName parameter, which creates a CIM session using WSMan. If you specify this parameter -without specifying the ComputerName parameter, or if you specify a CIM session created using DCOM -protocol, you will get an error, because the DCOM protocol does not support the ResourceURI -parameter. +**ResourceUri** can only be used with CIM sessions created using the WSMan protocol, or when +specifying the **ComputerName** parameter, which creates a CIM session using WSMan. If you specify +this parameter without specifying the **ComputerName** parameter, or if you specify a CIM session +created using DCOM protocol, you will get an error, because the DCOM protocol does not support the +**ResourceUri** parameter. If both the **ResourceUri** parameter and the **Filter** parameter are specified, the **Filter** parameter is ignored. diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/About.md b/reference/7.4/Microsoft.PowerShell.Core/About/About.md index ed49ce71c6c8..3b4ff768cc5f 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/About.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/About.md @@ -150,7 +150,7 @@ Describes the PowerShell debugger. ### [about_Do](about_Do.md) -Runs a statement list one or more times, subject to a `While` or `Until` +Runs a statement list one or more times, subject to a `while` or `until` condition. ### [about_Enum](about_Enum.md) @@ -268,8 +268,8 @@ expression in the background without interacting with the current session. ### [about_Join](about_Join.md) -Describes how the join operator (-join) combines multiple strings into a single -string. +Describes how the join operator (`-join`) combines multiple strings into a +single string. ### [about_Language_Keywords](about_Language_Keywords.md) @@ -398,8 +398,8 @@ Describes how to create and use a PowerShell profile. ### [about_Prompts](about_Prompts.md) -Describes the `Prompt` function and demonstrates how to create a custom -`Prompt` function. +Describes the `prompt` function and demonstrates how to create a custom +`prompt` function. ### [about_Properties](about_Properties.md) @@ -426,7 +426,7 @@ The automatic variable that contains the current object in the pipeline object. ### [about_PSModulePath](about_PSModulePath.md) -This article the purpose and usage of the `$env:PSModulePath` environment +This article the purpose and usage of the `$Env:PSModulePath` environment variable. ### [about_PSSession_Details](about_PSSession_Details.md) diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md index f0f2346e86bb..147f2ac9ac64 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md @@ -3,7 +3,7 @@ description: Describes the features of PowerShell that use ANSI escape sequences Locale: en-US ms.date: 08/27/2024 schema: 2.0.0 -title: about_ANSI_terminals +title: about_ANSI_Terminals --- # about_ANSI_Terminals @@ -230,7 +230,7 @@ in the `bash` process, outside of the PowerShell host, the output isn't affected by **OutputRendering**. ```bash -pwsh -noprofile -command 'Get-ChildItem' > out.txt +pwsh -NoProfile -Command 'Get-ChildItem' > out.txt ``` When you inspect the contents of `out.txt` you see the ANSI escape sequences. @@ -239,7 +239,7 @@ By contrast, when redirection occurs within the PowerShell session, **OutputRendering** affects the redirected output. ```bash -pwsh -noprofile -command 'Get-ChildItem > out.txt' +pwsh -NoProfile -Command 'Get-ChildItem > out.txt' ``` When you inspect the contents of `out.txt` there are no ANSI escape sequences. @@ -249,13 +249,13 @@ When you inspect the contents of `out.txt` there are no ANSI escape sequences. Support for ANSI escape sequences can be turned off using the **TERM** or **NO_COLOR** environment variables. -The following values of `$env:TERM` change the behavior as follows: +The following values of `$Env:TERM` change the behavior as follows: - `dumb` - sets `$Host.UI.SupportsVirtualTerminal = $false` - `xterm-mono` - sets `$PSStyle.OutputRendering = PlainText` - `xterm` - sets `$PSStyle.OutputRendering = PlainText` -If `$env:NO_COLOR` exists, then `$PSStyle.OutputRendering` is set to +If `$Env:NO_COLOR` exists, then `$PSStyle.OutputRendering` is set to **PlainText**. For more information about the **NO_COLOR** environment variable, see [https://no-color.org/][04]. diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Alias_Provider.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Alias_Provider.md index 880a7d095f81..ef9f5297283b 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Alias_Provider.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Alias_Provider.md @@ -149,7 +149,7 @@ current location is in the `Alias:` drive, the `-Path` parameter is not needed. This command also uses the `-Options` dynamic parameter to set the **AllScope** option on the alias. The `-Options` parameter is available in the `New-Item` cmdlet only when you are in the `Alias:` drive. The dot (`.`) indicates the -current directory, which is the alias drive. +current directory, which is the `Alias:` drive. ``` PS Alias:\> New-Item -Path . -Name serv -Value Get-Service -Options "AllScope" @@ -161,7 +161,7 @@ You can create an alias for any item that invokes a command. This command creates the `np` alias for `Notepad.exe`. ```powershell -New-Item -Path Alias:np -Value c:\windows\notepad.exe +New-Item -Path Alias:np -Value C:\windows\notepad.exe ``` ### Create an alias to a new function @@ -177,7 +177,7 @@ When the command is complete, you can use either `CD32` or `go` to invoke the function. ```powershell -function CD32 {Set-Location -Path c:\windows\system32} +function CD32 {Set-Location -Path C:\windows\system32} Set-Item -Path Alias:go -Value CD32 ``` @@ -313,7 +313,7 @@ Get-Help Get-ChildItem ``` ```powershell -Get-Help Get-ChildItem -Path alias: +Get-Help Get-ChildItem -Path Alias: ``` ## See also diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md index 606cca63b083..b69a9ad21c68 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md @@ -227,7 +227,7 @@ following example, the negative value can't be cast to an unsigned integer, and the unsigned integer is too large to be cast to `Int32`: ```powershell -([int32]::minvalue + [uint32]::maxvalue).GetType().FullName +([int32]::MinValue + [uint32]::MaxValue).GetType().FullName ``` ```Output @@ -241,10 +241,10 @@ The `System.Decimal` type is an exception. If either operand has the **Decimal** value is an error. ```powershell -PS> [Decimal]::maxvalue +PS> [decimal]::MaxValue 79228162514264337593543950335 -PS> [Decimal]::maxvalue + 1 +PS> [decimal]::MaxValue + 1 RuntimeException: Value was either too large or too small for a Decimal. ``` @@ -454,12 +454,12 @@ InvalidOperation: A hash table can only be added to another hash table. Although the addition operators are very useful, use the assignment operators to add elements to hash tables and arrays. For more information see -[about_assignment_operators](about_Assignment_Operators.md). The following +[about_Assignment_Operators](about_Assignment_Operators.md). The following examples use the `+=` assignment operator to add items to an array: ```powershell $array = @() -(0..2).foreach{ $array += $_ } +(0..2).ForEach{ $array += $_ } $array ``` @@ -497,7 +497,7 @@ The following examples show how to use the arithmetic operators in expressions with PowerShell commands: ```powershell -(Get-Date) + (New-TimeSpan -day 1) +(Get-Date) + (New-TimeSpan -Day 1) ``` The parenthesis operator forces the evaluation of the `Get-Date` cmdlet and the @@ -505,7 +505,7 @@ evaluation of the `New-TimeSpan -Day 1` cmdlet expression, in that order. Both results are then added using the `+` operator. ```powershell -Get-Process | Where-Object { ($_.ws * 2) -gt 50mb } +Get-Process | Where-Object { ($_.WS * 2) -gt 50mb } ``` ```Output @@ -519,7 +519,7 @@ Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName 967 30 58804 59496 416 930.97 2508 WINWORD ``` -In the above expression, each process working space (`$_.ws`) is multiplied by +In the above expression, each process working space (`$_.WS`) is multiplied by `2`; and, the result, compared against `50mb` to see if it's greater than that. ## Bitwise operators @@ -540,7 +540,7 @@ PowerShell supports the following bitwise operators. | `-band` | Bitwise AND | `10 -band 3` | 2 | | `-bor` | Bitwise OR (inclusive) | `10 -bor 3` | 11 | | `-bxor` | Bitwise OR (exclusive) | `10 -bxor 3` | 9 | -| `-bnot` | Bitwise NOT | `-bNot 10` | -11 | +| `-bnot` | Bitwise NOT | `-bnot 10` | -11 | | `-shl` | Shift-left | `102 -shl 2` | 408 | | `-shr` | Shift-right | `102 -shr 1` | 51 | @@ -587,7 +587,7 @@ For example, the binary complement of 0 is -1, the maximum unsigned integer (0xFFFFFFFF), and the binary complement of -1 is 0. ```powershell --bNot 10 +-bnot 10 ``` ```Output diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Arrays.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Arrays.md index 5cbe690a6757..4b2647bcb28d 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Arrays.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Arrays.md @@ -305,7 +305,7 @@ value in an array, type: ```powershell $a = 0..9 -for ($i = 0; $i -le ($a.length - 1); $i += 2) { +for ($i = 0; $i -le ($a.Length - 1); $i += 2) { $a[$i] } ``` @@ -346,11 +346,11 @@ In PowerShell, arrays have three properties that indicate the number of items contained in the array. - **Count** - This property is the most commonly used property to determine the - number of items in any collection, not just an array. It's an `[Int32]` type + number of items in any collection, not just an array. It's an `[int32]` type value. In Windows PowerShell 5.1 (and older) **Count** alias property for **Length**. -- **Length** - This property is an `[Int32]` type value. This contains the same +- **Length** - This property is an `[int32]` type value. This contains the same value as **Count**. > [!NOTE] @@ -359,7 +359,7 @@ contained in the array. > string is the number of characters in the string. But the **Count** > property is always `1`. -- **Longlength** - This property is an `[Int64]` type value. Use this property +- **LongLength** - This property is an `[int64]` type value. Use this property for arrays containing more than 2,147,483,647 elements. ```powershell @@ -408,8 +408,8 @@ Multidimensional arrays are stored in [row-major order][14]. The following example shows how to create a truly multidimensional array. ```powershell -[string[,]]$rank2 = [string[,]]::New(3,2) -$rank2.rank +[string[,]]$rank2 = [string[,]]::new(3,2) +$rank2.Rank $rank2.Length $rank2[0,0] = 'a' $rank2[0,1] = 'b' @@ -487,7 +487,7 @@ True In this example, `$intA` is explicitly typed to contain integers. ```powershell -[Int[]] $intA = 1, 2, 3 +[int[]] $intA = 1, 2, 3 $intA.Clear() $intA ``` @@ -552,7 +552,7 @@ For more information about the behavior of **ArgumentList**, see The `ForEach()` method can be used to cast the elements to a different type; the following example shows how to convert a list of string dates to -`[DateTime]` type. +`[datetime]` type. ```powershell ("1/1/2017", "2/1/2017", "3/1/2017").ForEach([datetime]) @@ -680,7 +680,7 @@ to return. ```powershell # Get the zip files in the current users profile, sorted by LastAccessTime -$Zips = dir $env:userprofile -Recurse '*.zip' | Sort-Object LastAccessTime +$Zips = dir $Env:USERPROFILE -Recurse '*.zip' | Sort-Object LastAccessTime # Get the least accessed file over 100MB $Zips.Where({$_.Length -gt 100MB}, 'Default', 1) ``` @@ -876,7 +876,7 @@ create the `$t` array with all the elements in the `$a` array except for the value at index position 2, type: ```powershell -$t = $a[0,1 + 3..($a.length - 1)] +$t = $a[0,1 + 3..($a.Length - 1)] ``` To combine two arrays into a single array, use the plus operator (`+`). The @@ -1101,7 +1101,7 @@ LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;} ## See also - [about_For][05] -- [about_ForEach][06] +- [about_Foreach][06] - [about_Hash_Tables][07] - [about_Member-Access_Enumeration][09] - [about_Operators][11] @@ -1114,7 +1114,7 @@ LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;} [03]: about_Assignment_Operators.md [04]: about_Booleans.md [05]: about_For.md -[06]: about_ForEach.md +[06]: about_Foreach.md [07]: about_Hash_Tables.md [08]: about_Intrinsic_Members.md [09]: about_Member-Access_Enumeration.md diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md index f8b0822ad313..0d69531a1746 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md @@ -82,7 +82,7 @@ pipeline to a variable. For example, the following command sorts the services on the computer and then assigns the sorted services to the `$a` variable: ```powershell -$a = Get-Service | Sort-Object -Property name +$a = Get-Service | Sort-Object -Property Name ``` You can also assign the value created by a statement to a variable, as in the diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md index 6009937e40df..e41da8dcca44 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md @@ -211,8 +211,8 @@ non-zero integer. ### `$foreach` -Contains the enumerator (not the resulting values) of a [ForEach][56] loop. The -`$foreach` variable exists only while the `ForEach` loop is running; it's +Contains the enumerator (not the resulting values) of a [foreach][56] loop. The +`$foreach` variable exists only while the `foreach` loop is running; it's deleted after the loop is completed. Enumerators contain properties and methods you can use to retrieve loop values @@ -222,19 +222,19 @@ and change the current loop iteration. For more information, see ### `$HOME` Contains the full path of the user's home directory. On Windows, this variable -uses the value of the `"$env:USERPROFILE"` Windows environment variable, +uses the value of the `"$Env:USERPROFILE"` Windows environment variable, typically `C:\Users\`. On Unix, this variable uses the value of the `HOME` environment variable. > [!IMPORTANT] > Windows can redirect the location of the user's profile. This means that -> `$HOME` may not have the same value as `"$env:HOMEDRIVE$env:HOMEPATH"`. +> `$HOME` may not have the same value as `"$Env:HOMEDRIVE$Env:HOMEPATH"`. ### `$Host` Contains an object that represents the current host application for PowerShell. You can use this variable to represent the current host in commands or to -display or change the properties of the host, such as `$Host.version` or +display or change the properties of the host, such as `$Host.Version` or `$Host.CurrentCulture`, or `$Host.UI.RawUI.BackGroundColor = "Red"`. > [!NOTE] @@ -489,7 +489,7 @@ Test-Path $PROFILE Or, you can use it in a command to create a profile: ```powershell -New-Item -ItemType file -Path $PROFILE -Force +New-Item -ItemType File -Path $PROFILE -Force ``` You can use it in a command to open the profile in **notepad.exe**: @@ -679,8 +679,8 @@ Contains a stack trace for the most recent error. ### `$switch` -Contains the enumerator not the resulting values of a `Switch` statement. The -`$switch` variable exists only while the `Switch` statement is running; it's +Contains the enumerator not the resulting values of a `switch` statement. The +`$switch` variable exists only while the `switch` statement is running; it's deleted when the `switch` statement completes execution. For more information, see [about_Switch][71]. @@ -1133,7 +1133,7 @@ Default (Current): End [53]: about_CommonParameters.md [54]: about_comparison_operators.md [55]: about_Continue.md -[56]: about_ForEach.md +[56]: about_Foreach.md [57]: about_Functions_Advanced_Methods.md [58]: about_Functions_Advanced_Parameters.md [59]: about_Functions_Advanced.md diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Booleans.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Booleans.md index c8bdd0f281c2..06c8d4a08cd7 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Booleans.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Booleans.md @@ -91,7 +91,7 @@ Examples: # Empty collections PS> [bool]@() False -PS> [bool](Get-ChildItem | Where-Object Name -eq 'Non-existent-File.txt') +PS> [bool](Get-ChildItem | Where-Object Name -EQ 'Non-existent-File.txt') False # Single-element collections PS> $a = @(0) diff --git a/reference/7.4/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md b/reference/7.4/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md index beb3448375d2..7f3209fa27d2 100644 --- a/reference/7.4/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md +++ b/reference/7.4/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md @@ -33,76 +33,76 @@ The following list itemizes the cmdlets that support calculated properties and the key-value pairs that each cmdlet supports. - `Compare-Object` - - `expression` + - `Expression` - `ConvertTo-Html` - - `name`/`label` - optional (added in PowerShell 6.x) - - `expression` - - `width` - optional - - `alignment` - optional + - `Name`/`Label` - optional (added in PowerShell 6.x) + - `Expression` + - `Width` - optional + - `Alignment` - optional - `Format-Custom` - - `expression` - - `depth` - optional + - `Expression` + - `Depth` - optional - `Format-List` - - `name`/`label` - optional - - `expression` - - `formatstring` - optional + - `Name`/`Label` - optional + - `Expression` + - `FormatString` - optional This same set of key-value pairs also apply to calculated property values passed to the **GroupBy** parameter for all `Format-*` cmdlets. - `Format-Table` - - `name`/`label` - optional - - `expression` - - `formatstring` - optional - - `width` - optional - - `alignment` - optional + - `Name`/`Label` - optional + - `Expression` + - `FormatString` - optional + - `Width` - optional + - `Alignment` - optional - `Format-Wide` - - `expression` - - `formatstring` - optional + - `Expression` + - `FormatString` - optional - `Group-Object` - - `expression` + - `Expression` - `Measure-Object` - Only supports a script block for the expression, not a hashtable. - Not supported in PowerShell 5.1 and older. - `Select-Object` - - `name`/`label` - optional - - `expression` + - `Name`/`Label` - optional + - `Expression` - `Sort-Object` - - `expression` - - `ascending`/`descending` - optional + - `Expression` + - `Ascending`/`Descending` - optional > [!NOTE] -> The value of the `expression` can be a script block instead of a +> The value of the `Expression` can be a script block instead of a > hashtable. For more information, see the [Notes][02] section. ## Hashtable key definitions -- `name`/`label` - Specifies the name of the property being created. You can - use `name` or its alias, `label`, interchangeably. -- `expression` - A string or script block used to calculate the value of the - new property. If the `expression` is a string, the value is interpreted as a +- `Name`/`Label` - Specifies the name of the property being created. You can + use `Name` or its alias, `Label`, interchangeably. +- `Expression` - A string or script block used to calculate the value of the + new property. If the `Expression` is a string, the value is interpreted as a property name on the input object. This is a shorter option than - `expression = { $_. }`. -- `alignment` - Used by cmdlets that produce tabular output to define how the - values are displayed in a column. The value must be `'left'`, `'center'`, or - `'right'`. -- `formatstring` - Specifies a format string that defines how the value is + `Expression = { $_. }`. +- `Alignment` - Used by cmdlets that produce tabular output to define how the + values are displayed in a column. The value must be `'Left'`, `'Center'`, or + `'Right'`. +- `FormatString` - Specifies a format string that defines how the value is formatted for output. For more information about format strings, see [Format types in .NET][01]. -- `width` - Specifies the maximum width column in a table when the value is +- `Width` - Specifies the maximum width column in a table when the value is displayed. The value must be greater than `0`. -- `depth` - The **Depth** parameter of `Format-Custom` specifies the depth of - expansion for all properties. The `depth` key allows you to specify the +- `Depth` - The **Depth** parameter of `Format-Custom` specifies the depth of + expansion for all properties. The `Depth` key allows you to specify the depth of expansion per property. -- `ascending` / `descending` - Allows you to specify the order of sorting for +- `Ascending` / `Descending` - Allows you to specify the order of sorting for one or more properties. These are boolean values. You don't need to spell out the hashtable keys as long as the specified name @@ -119,7 +119,7 @@ directly, the values are compared to the result of the arithmetic operation (modulus of 2). ```powershell -Compare-Object @{p=1} @{p=2} -property @{ Expression = { $_.p % 2 } } +Compare-Object @{p=1} @{p=2} -Property @{ Expression = { $_.p % 2 } } ``` ```Output @@ -139,9 +139,9 @@ Get-Alias | ConvertTo-Html Name, Definition, @{ - name='ParameterCount' - expr={$_.Parameters.Keys.Count} - align='center' + Name='ParameterCount' + Expr={$_.Parameters.Keys.Count} + Align='Center' } | Out-File .\aliases.htm -Force ``` @@ -155,15 +155,15 @@ the number parameters for each aliased command. The values of `Format-Custom` provides a custom view of an object in a format similar to a class definition. More complex objects can contain members that are deeply nested with complex types. The **Depth** parameter of `Format-Custom` specifies -the depth of expansion for all properties. The `depth` key allows you to +the depth of expansion for all properties. The `Depth` key allows you to specify the depth of expansion per property. -In this example, the `depth` key simplifies the custom output for the +In this example, the `Depth` key simplifies the custom output for the `Get-Date` cmdlet. `Get-Date` returns a **DateTime** object. The **Date** property of this object is also a **DateTime** object, so the object is nested. ```powershell -Get-Date | Format-Custom @{expr={$_.Date};depth=1},TimeOfDay +Get-Date | Format-Custom @{Expr={$_.Date};Depth=1},TimeOfDay ``` ```Output @@ -212,16 +212,16 @@ the output from `Get-ChildItem`. ```powershell Get-ChildItem *.json -File | - Format-List Fullname, + Format-List FullName, @{ - name='Modified' - expression={$_.LastWriteTime} - formatstring='O' + Name='Modified' + Expression={$_.LastWriteTime} + FormatString='O' }, @{ - name='Size' - expression={$_.Length/1KB} - formatstring='N2' + Name='Size' + Expression={$_.Length/1KB} + FormatString='N2' } ``` @@ -246,11 +246,11 @@ classify the files by the content type. ```powershell Get-ChildItem -File | - Sort-Object extension | + Sort-Object Extension | Format-Table Name, Length -GroupBy @{ - name='Type' - expression={ - switch ($_.extension) { + Name='Type' + Expression={ + switch ($_.Extension) { '.md' {'Content'} '' {'Metacontent'} '.ps1' {'Automation'} @@ -312,7 +312,7 @@ value. ```powershell Get-ChildItem -File | - Format-Wide -Property @{e={'{0} ({1:N2}kb)' -f $_.name,($_.length/1kb)}} + Format-Wide -Property @{e={'{0} ({1:N2}kb)' -f $_.Name,($_.Length/1kb)}} ``` ```Output @@ -335,10 +335,10 @@ of files of each content type. ```powershell Get-ChildItem -File | - Sort-Object extension | + Sort-Object Extension | Group-Object -NoElement -Property @{ - expression={ - switch ($_.extension) { + Expression={ + switch ($_.Extension) { '.md' {'Content'} '' {'Metacontent'} '.ps1' {'Automation'} @@ -400,8 +400,8 @@ $aliases = Get-Alias c* | Select-Object Name, Definition, @{ - name='ParameterCount' - expr={$_.Parameters.Keys.Count} + Name='ParameterCount' + Expr={$_.Parameters.Keys.Count} } $aliases | Get-Member $aliases @@ -451,7 +451,7 @@ property. This example sorts data from a CSV file in ascending order by ```powershell Import-Csv C:\temp\sales-data.csv | - Sort-Object Date, @{expr={$_.UnitsSold}; desc=$true}, Salesperson | + Sort-Object Date, @{Expr={$_.UnitsSold}; Desc=$true}, Salesperson | Select-Object Date, Salesperson, UnitsSold ``` diff --git a/reference/7.5/CimCmdlets/Set-CimInstance.md b/reference/7.5/CimCmdlets/Set-CimInstance.md index 2fafa248fc89..c37e8e31c72b 100644 --- a/reference/7.5/CimCmdlets/Set-CimInstance.md +++ b/reference/7.5/CimCmdlets/Set-CimInstance.md @@ -236,9 +236,9 @@ Accept wildcard characters: False ### -Namespace -Specifies the namespace for the CIM operation. The default namespace is root/cimv2. You can use tab -completion to browse the list of namespaces, because PowerShell gets a list of namespaces from the -local WMI server to provide the list of namespaces. +Specifies the namespace for the CIM operation. The default namespace is **root/CIMV2**. You can use +tab completion to browse the list of namespaces, because PowerShell gets a list of namespaces from +the local WMI server to provide the list of namespaces. ```yaml Type: System.String @@ -362,11 +362,11 @@ A URI consists of a prefix and a path to a resource. For example: By default, if you do not specify this parameter, the DMTF standard resource URI `http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/` is used and the class name is appended to it. -ResourceURI can only be used with CIM sessions created using the WSMan protocol, or when specifying -the ComputerName parameter, which creates a CIM session using WSMan. If you specify this parameter -without specifying the ComputerName parameter, or if you specify a CIM session created using DCOM -protocol, you will get an error, because the DCOM protocol does not support the ResourceURI -parameter. +**ResourceUri** can only be used with CIM sessions created using the WSMan protocol, or when +specifying the **ComputerName** parameter, which creates a CIM session using WSMan. If you specify +this parameter without specifying the **ComputerName** parameter, or if you specify a CIM session +created using DCOM protocol, you will get an error, because the DCOM protocol does not support the +**ResourceUri** parameter. If both the **ResourceUri** parameter and the **Filter** parameter are specified, the **Filter** parameter is ignored. diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/About.md b/reference/7.5/Microsoft.PowerShell.Core/About/About.md index 65694cc1ae08..805f8b912fdd 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/About.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/About.md @@ -150,7 +150,7 @@ Describes the PowerShell debugger. ### [about_Do](about_Do.md) -Runs a statement list one or more times, subject to a `While` or `Until` +Runs a statement list one or more times, subject to a `while` or `until` condition. ### [about_Enum](about_Enum.md) @@ -268,8 +268,8 @@ expression in the background without interacting with the current session. ### [about_Join](about_Join.md) -Describes how the join operator (-join) combines multiple strings into a single -string. +Describes how the join operator (`-join`) combines multiple strings into a +single string. ### [about_Language_Keywords](about_Language_Keywords.md) @@ -398,8 +398,8 @@ Describes how to create and use a PowerShell profile. ### [about_Prompts](about_Prompts.md) -Describes the `Prompt` function and demonstrates how to create a custom -`Prompt` function. +Describes the `prompt` function and demonstrates how to create a custom +`prompt` function. ### [about_Properties](about_Properties.md) @@ -426,7 +426,7 @@ The automatic variable that contains the current object in the pipeline object. ### [about_PSModulePath](about_PSModulePath.md) -This article the purpose and usage of the `$env:PSModulePath` environment +This article the purpose and usage of the `$Env:PSModulePath` environment variable. ### [about_PSSession_Details](about_PSSession_Details.md) diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md index f0f2346e86bb..147f2ac9ac64 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md @@ -3,7 +3,7 @@ description: Describes the features of PowerShell that use ANSI escape sequences Locale: en-US ms.date: 08/27/2024 schema: 2.0.0 -title: about_ANSI_terminals +title: about_ANSI_Terminals --- # about_ANSI_Terminals @@ -230,7 +230,7 @@ in the `bash` process, outside of the PowerShell host, the output isn't affected by **OutputRendering**. ```bash -pwsh -noprofile -command 'Get-ChildItem' > out.txt +pwsh -NoProfile -Command 'Get-ChildItem' > out.txt ``` When you inspect the contents of `out.txt` you see the ANSI escape sequences. @@ -239,7 +239,7 @@ By contrast, when redirection occurs within the PowerShell session, **OutputRendering** affects the redirected output. ```bash -pwsh -noprofile -command 'Get-ChildItem > out.txt' +pwsh -NoProfile -Command 'Get-ChildItem > out.txt' ``` When you inspect the contents of `out.txt` there are no ANSI escape sequences. @@ -249,13 +249,13 @@ When you inspect the contents of `out.txt` there are no ANSI escape sequences. Support for ANSI escape sequences can be turned off using the **TERM** or **NO_COLOR** environment variables. -The following values of `$env:TERM` change the behavior as follows: +The following values of `$Env:TERM` change the behavior as follows: - `dumb` - sets `$Host.UI.SupportsVirtualTerminal = $false` - `xterm-mono` - sets `$PSStyle.OutputRendering = PlainText` - `xterm` - sets `$PSStyle.OutputRendering = PlainText` -If `$env:NO_COLOR` exists, then `$PSStyle.OutputRendering` is set to +If `$Env:NO_COLOR` exists, then `$PSStyle.OutputRendering` is set to **PlainText**. For more information about the **NO_COLOR** environment variable, see [https://no-color.org/][04]. diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Alias_Provider.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Alias_Provider.md index 8f587a0c4ae5..559fdf30b075 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Alias_Provider.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Alias_Provider.md @@ -149,7 +149,7 @@ current location is in the `Alias:` drive, the `-Path` parameter is not needed. This command also uses the `-Options` dynamic parameter to set the **AllScope** option on the alias. The `-Options` parameter is available in the `New-Item` cmdlet only when you are in the `Alias:` drive. The dot (`.`) indicates the -current directory, which is the alias drive. +current directory, which is the `Alias:` drive. ``` PS Alias:\> New-Item -Path . -Name serv -Value Get-Service -Options "AllScope" @@ -161,7 +161,7 @@ You can create an alias for any item that invokes a command. This command creates the `np` alias for `Notepad.exe`. ```powershell -New-Item -Path Alias:np -Value c:\windows\notepad.exe +New-Item -Path Alias:np -Value C:\windows\notepad.exe ``` ### Create an alias to a new function @@ -177,7 +177,7 @@ When the command is complete, you can use either `CD32` or `go` to invoke the function. ```powershell -function CD32 {Set-Location -Path c:\windows\system32} +function CD32 {Set-Location -Path C:\windows\system32} Set-Item -Path Alias:go -Value CD32 ``` @@ -313,7 +313,7 @@ Get-Help Get-ChildItem ``` ```powershell -Get-Help Get-ChildItem -Path alias: +Get-Help Get-ChildItem -Path Alias: ``` ## See also diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md index 53ea1cbd7d7c..0f6048cd00d7 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md @@ -227,7 +227,7 @@ following example, the negative value can't be cast to an unsigned integer, and the unsigned integer is too large to be cast to `Int32`: ```powershell -([int32]::minvalue + [uint32]::maxvalue).GetType().FullName +([int32]::MinValue + [uint32]::MaxValue).GetType().FullName ``` ```Output @@ -241,10 +241,10 @@ The `System.Decimal` type is an exception. If either operand has the **Decimal** value is an error. ```powershell -PS> [Decimal]::maxvalue +PS> [decimal]::MaxValue 79228162514264337593543950335 -PS> [Decimal]::maxvalue + 1 +PS> [decimal]::MaxValue + 1 RuntimeException: Value was either too large or too small for a Decimal. ``` @@ -454,12 +454,12 @@ InvalidOperation: A hash table can only be added to another hash table. Although the addition operators are very useful, use the assignment operators to add elements to hash tables and arrays. For more information see -[about_assignment_operators](about_Assignment_Operators.md). The following +[about_Assignment_Operators](about_Assignment_Operators.md). The following examples use the `+=` assignment operator to add items to an array: ```powershell $array = @() -(0..2).foreach{ $array += $_ } +(0..2).ForEach{ $array += $_ } $array ``` @@ -497,7 +497,7 @@ The following examples show how to use the arithmetic operators in expressions with PowerShell commands: ```powershell -(Get-Date) + (New-TimeSpan -day 1) +(Get-Date) + (New-TimeSpan -Day 1) ``` The parenthesis operator forces the evaluation of the `Get-Date` cmdlet and the @@ -505,7 +505,7 @@ evaluation of the `New-TimeSpan -Day 1` cmdlet expression, in that order. Both results are then added using the `+` operator. ```powershell -Get-Process | Where-Object { ($_.ws * 2) -gt 50mb } +Get-Process | Where-Object { ($_.WS * 2) -gt 50mb } ``` ```Output @@ -519,7 +519,7 @@ Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName 967 30 58804 59496 416 930.97 2508 WINWORD ``` -In the above expression, each process working space (`$_.ws`) is multiplied by +In the above expression, each process working space (`$_.WS`) is multiplied by `2`; and, the result, compared against `50mb` to see if it's greater than that. ## Bitwise operators @@ -540,7 +540,7 @@ PowerShell supports the following bitwise operators. | `-band` | Bitwise AND | `10 -band 3` | 2 | | `-bor` | Bitwise OR (inclusive) | `10 -bor 3` | 11 | | `-bxor` | Bitwise OR (exclusive) | `10 -bxor 3` | 9 | -| `-bnot` | Bitwise NOT | `-bNot 10` | -11 | +| `-bnot` | Bitwise NOT | `-bnot 10` | -11 | | `-shl` | Shift-left | `102 -shl 2` | 408 | | `-shr` | Shift-right | `102 -shr 1` | 51 | @@ -587,7 +587,7 @@ For example, the binary complement of 0 is -1, the maximum unsigned integer (0xFFFFFFFF), and the binary complement of -1 is 0. ```powershell --bNot 10 +-bnot 10 ``` ```Output diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Arrays.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Arrays.md index 77070f700962..52a766872867 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Arrays.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Arrays.md @@ -305,7 +305,7 @@ value in an array, type: ```powershell $a = 0..9 -for ($i = 0; $i -le ($a.length - 1); $i += 2) { +for ($i = 0; $i -le ($a.Length - 1); $i += 2) { $a[$i] } ``` @@ -346,11 +346,11 @@ In PowerShell, arrays have three properties that indicate the number of items contained in the array. - **Count** - This property is the most commonly used property to determine the - number of items in any collection, not just an array. It's an `[Int32]` type + number of items in any collection, not just an array. It's an `[int32]` type value. In Windows PowerShell 5.1 (and older) **Count** alias property for **Length**. -- **Length** - This property is an `[Int32]` type value. This contains the same +- **Length** - This property is an `[int32]` type value. This contains the same value as **Count**. > [!NOTE] @@ -359,7 +359,7 @@ contained in the array. > string is the number of characters in the string. But the **Count** > property is always `1`. -- **Longlength** - This property is an `[Int64]` type value. Use this property +- **LongLength** - This property is an `[int64]` type value. Use this property for arrays containing more than 2,147,483,647 elements. ```powershell @@ -408,8 +408,8 @@ Multidimensional arrays are stored in [row-major order][14]. The following example shows how to create a truly multidimensional array. ```powershell -[string[,]]$rank2 = [string[,]]::New(3,2) -$rank2.rank +[string[,]]$rank2 = [string[,]]::new(3,2) +$rank2.Rank $rank2.Length $rank2[0,0] = 'a' $rank2[0,1] = 'b' @@ -487,7 +487,7 @@ True In this example, `$intA` is explicitly typed to contain integers. ```powershell -[Int[]] $intA = 1, 2, 3 +[int[]] $intA = 1, 2, 3 $intA.Clear() $intA ``` @@ -552,7 +552,7 @@ For more information about the behavior of **ArgumentList**, see The `ForEach()` method can be used to cast the elements to a different type; the following example shows how to convert a list of string dates to -`[DateTime]` type. +`[datetime]` type. ```powershell ("1/1/2017", "2/1/2017", "3/1/2017").ForEach([datetime]) @@ -680,7 +680,7 @@ to return. ```powershell # Get the zip files in the current users profile, sorted by LastAccessTime -$Zips = dir $env:userprofile -Recurse '*.zip' | Sort-Object LastAccessTime +$Zips = dir $Env:USERPROFILE -Recurse '*.zip' | Sort-Object LastAccessTime # Get the least accessed file over 100MB $Zips.Where({$_.Length -gt 100MB}, 'Default', 1) ``` @@ -876,7 +876,7 @@ create the `$t` array with all the elements in the `$a` array except for the value at index position 2, type: ```powershell -$t = $a[0,1 + 3..($a.length - 1)] +$t = $a[0,1 + 3..($a.Length - 1)] ``` To combine two arrays into a single array, use the plus operator (`+`). The @@ -1101,7 +1101,7 @@ LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;} ## See also - [about_For][05] -- [about_ForEach][06] +- [about_Foreach][06] - [about_Hash_Tables][07] - [about_Member-Access_Enumeration][09] - [about_Operators][11] @@ -1114,7 +1114,7 @@ LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;} [03]: about_Assignment_Operators.md [04]: about_Booleans.md [05]: about_For.md -[06]: about_ForEach.md +[06]: about_Foreach.md [07]: about_Hash_Tables.md [08]: about_Intrinsic_Members.md [09]: about_Member-Access_Enumeration.md diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md index 2e393200a84e..bbab74dbce30 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md @@ -82,7 +82,7 @@ pipeline to a variable. For example, the following command sorts the services on the computer and then assigns the sorted services to the `$a` variable: ```powershell -$a = Get-Service | Sort-Object -Property name +$a = Get-Service | Sort-Object -Property Name ``` You can also assign the value created by a statement to a variable, as in the diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md index 9641e0acb0dd..c13d6c9369ad 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md @@ -211,8 +211,8 @@ non-zero integer. ### `$foreach` -Contains the enumerator (not the resulting values) of a [ForEach][56] loop. The -`$foreach` variable exists only while the `ForEach` loop is running; it's +Contains the enumerator (not the resulting values) of a [foreach][56] loop. The +`$foreach` variable exists only while the `foreach` loop is running; it's deleted after the loop is completed. Enumerators contain properties and methods you can use to retrieve loop values @@ -222,19 +222,19 @@ and change the current loop iteration. For more information, see ### `$HOME` Contains the full path of the user's home directory. On Windows, this variable -uses the value of the `"$env:USERPROFILE"` Windows environment variable, +uses the value of the `"$Env:USERPROFILE"` Windows environment variable, typically `C:\Users\`. On Unix, this variable uses the value of the `HOME` environment variable. > [!IMPORTANT] > Windows can redirect the location of the user's profile. This means that -> `$HOME` may not have the same value as `"$env:HOMEDRIVE$env:HOMEPATH"`. +> `$HOME` may not have the same value as `"$Env:HOMEDRIVE$Env:HOMEPATH"`. ### `$Host` Contains an object that represents the current host application for PowerShell. You can use this variable to represent the current host in commands or to -display or change the properties of the host, such as `$Host.version` or +display or change the properties of the host, such as `$Host.Version` or `$Host.CurrentCulture`, or `$Host.UI.RawUI.BackGroundColor = "Red"`. > [!NOTE] @@ -489,7 +489,7 @@ Test-Path $PROFILE Or, you can use it in a command to create a profile: ```powershell -New-Item -ItemType file -Path $PROFILE -Force +New-Item -ItemType File -Path $PROFILE -Force ``` You can use it in a command to open the profile in **notepad.exe**: @@ -679,8 +679,8 @@ Contains a stack trace for the most recent error. ### `$switch` -Contains the enumerator not the resulting values of a `Switch` statement. The -`$switch` variable exists only while the `Switch` statement is running; it's +Contains the enumerator not the resulting values of a `switch` statement. The +`$switch` variable exists only while the `switch` statement is running; it's deleted when the `switch` statement completes execution. For more information, see [about_Switch][71]. @@ -1133,7 +1133,7 @@ Default (Current): End [53]: about_CommonParameters.md [54]: about_comparison_operators.md [55]: about_Continue.md -[56]: about_ForEach.md +[56]: about_Foreach.md [57]: about_Functions_Advanced_Methods.md [58]: about_Functions_Advanced_Parameters.md [59]: about_Functions_Advanced.md diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Booleans.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Booleans.md index ebcc44b752a5..1895494021c4 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Booleans.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Booleans.md @@ -91,7 +91,7 @@ Examples: # Empty collections PS> [bool]@() False -PS> [bool](Get-ChildItem | Where-Object Name -eq 'Non-existent-File.txt') +PS> [bool](Get-ChildItem | Where-Object Name -EQ 'Non-existent-File.txt') False # Single-element collections PS> $a = @(0) diff --git a/reference/7.5/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md b/reference/7.5/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md index 9141db02724e..eeb07fc9e7b2 100644 --- a/reference/7.5/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md +++ b/reference/7.5/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md @@ -33,76 +33,76 @@ The following list itemizes the cmdlets that support calculated properties and the key-value pairs that each cmdlet supports. - `Compare-Object` - - `expression` + - `Expression` - `ConvertTo-Html` - - `name`/`label` - optional (added in PowerShell 6.x) - - `expression` - - `width` - optional - - `alignment` - optional + - `Name`/`Label` - optional (added in PowerShell 6.x) + - `Expression` + - `Width` - optional + - `Alignment` - optional - `Format-Custom` - - `expression` - - `depth` - optional + - `Expression` + - `Depth` - optional - `Format-List` - - `name`/`label` - optional - - `expression` - - `formatstring` - optional + - `Name`/`Label` - optional + - `Expression` + - `FormatString` - optional This same set of key-value pairs also apply to calculated property values passed to the **GroupBy** parameter for all `Format-*` cmdlets. - `Format-Table` - - `name`/`label` - optional - - `expression` - - `formatstring` - optional - - `width` - optional - - `alignment` - optional + - `Name`/`Label` - optional + - `Expression` + - `FormatString` - optional + - `Width` - optional + - `Alignment` - optional - `Format-Wide` - - `expression` - - `formatstring` - optional + - `Expression` + - `FormatString` - optional - `Group-Object` - - `expression` + - `Expression` - `Measure-Object` - Only supports a script block for the expression, not a hashtable. - Not supported in PowerShell 5.1 and older. - `Select-Object` - - `name`/`label` - optional - - `expression` + - `Name`/`Label` - optional + - `Expression` - `Sort-Object` - - `expression` - - `ascending`/`descending` - optional + - `Expression` + - `Ascending`/`Descending` - optional > [!NOTE] -> The value of the `expression` can be a script block instead of a +> The value of the `Expression` can be a script block instead of a > hashtable. For more information, see the [Notes][02] section. ## Hashtable key definitions -- `name`/`label` - Specifies the name of the property being created. You can - use `name` or its alias, `label`, interchangeably. -- `expression` - A string or script block used to calculate the value of the - new property. If the `expression` is a string, the value is interpreted as a +- `Name`/`Label` - Specifies the name of the property being created. You can + use `Name` or its alias, `Label`, interchangeably. +- `Expression` - A string or script block used to calculate the value of the + new property. If the `Expression` is a string, the value is interpreted as a property name on the input object. This is a shorter option than - `expression = { $_. }`. -- `alignment` - Used by cmdlets that produce tabular output to define how the - values are displayed in a column. The value must be `'left'`, `'center'`, or - `'right'`. -- `formatstring` - Specifies a format string that defines how the value is + `Expression = { $_. }`. +- `Alignment` - Used by cmdlets that produce tabular output to define how the + values are displayed in a column. The value must be `'Left'`, `'Center'`, or + `'Right'`. +- `FormatString` - Specifies a format string that defines how the value is formatted for output. For more information about format strings, see [Format types in .NET][01]. -- `width` - Specifies the maximum width column in a table when the value is +- `Width` - Specifies the maximum width column in a table when the value is displayed. The value must be greater than `0`. -- `depth` - The **Depth** parameter of `Format-Custom` specifies the depth of - expansion for all properties. The `depth` key allows you to specify the +- `Depth` - The **Depth** parameter of `Format-Custom` specifies the depth of + expansion for all properties. The `Depth` key allows you to specify the depth of expansion per property. -- `ascending` / `descending` - Allows you to specify the order of sorting for +- `Ascending` / `Descending` - Allows you to specify the order of sorting for one or more properties. These are boolean values. You don't need to spell out the hashtable keys as long as the specified name @@ -119,7 +119,7 @@ directly, the values are compared to the result of the arithmetic operation (modulus of 2). ```powershell -Compare-Object @{p=1} @{p=2} -property @{ Expression = { $_.p % 2 } } +Compare-Object @{p=1} @{p=2} -Property @{ Expression = { $_.p % 2 } } ``` ```Output @@ -139,9 +139,9 @@ Get-Alias | ConvertTo-Html Name, Definition, @{ - name='ParameterCount' - expr={$_.Parameters.Keys.Count} - align='center' + Name='ParameterCount' + Expr={$_.Parameters.Keys.Count} + Align='Center' } | Out-File .\aliases.htm -Force ``` @@ -155,15 +155,15 @@ the number parameters for each aliased command. The values of `Format-Custom` provides a custom view of an object in a format similar to a class definition. More complex objects can contain members that are deeply nested with complex types. The **Depth** parameter of `Format-Custom` specifies -the depth of expansion for all properties. The `depth` key allows you to +the depth of expansion for all properties. The `Depth` key allows you to specify the depth of expansion per property. -In this example, the `depth` key simplifies the custom output for the +In this example, the `Depth` key simplifies the custom output for the `Get-Date` cmdlet. `Get-Date` returns a **DateTime** object. The **Date** property of this object is also a **DateTime** object, so the object is nested. ```powershell -Get-Date | Format-Custom @{expr={$_.Date};depth=1},TimeOfDay +Get-Date | Format-Custom @{Expr={$_.Date};Depth=1},TimeOfDay ``` ```Output @@ -212,16 +212,16 @@ the output from `Get-ChildItem`. ```powershell Get-ChildItem *.json -File | - Format-List Fullname, + Format-List FullName, @{ - name='Modified' - expression={$_.LastWriteTime} - formatstring='O' + Name='Modified' + Expression={$_.LastWriteTime} + FormatString='O' }, @{ - name='Size' - expression={$_.Length/1KB} - formatstring='N2' + Name='Size' + Expression={$_.Length/1KB} + FormatString='N2' } ``` @@ -246,11 +246,11 @@ classify the files by the content type. ```powershell Get-ChildItem -File | - Sort-Object extension | + Sort-Object Extension | Format-Table Name, Length -GroupBy @{ - name='Type' - expression={ - switch ($_.extension) { + Name='Type' + Expression={ + switch ($_.Extension) { '.md' {'Content'} '' {'Metacontent'} '.ps1' {'Automation'} @@ -312,7 +312,7 @@ value. ```powershell Get-ChildItem -File | - Format-Wide -Property @{e={'{0} ({1:N2}kb)' -f $_.name,($_.length/1kb)}} + Format-Wide -Property @{e={'{0} ({1:N2}kb)' -f $_.Name,($_.Length/1kb)}} ``` ```Output @@ -335,10 +335,10 @@ of files of each content type. ```powershell Get-ChildItem -File | - Sort-Object extension | + Sort-Object Extension | Group-Object -NoElement -Property @{ - expression={ - switch ($_.extension) { + Expression={ + switch ($_.Extension) { '.md' {'Content'} '' {'Metacontent'} '.ps1' {'Automation'} @@ -400,8 +400,8 @@ $aliases = Get-Alias c* | Select-Object Name, Definition, @{ - name='ParameterCount' - expr={$_.Parameters.Keys.Count} + Name='ParameterCount' + Expr={$_.Parameters.Keys.Count} } $aliases | Get-Member $aliases @@ -451,7 +451,7 @@ property. This example sorts data from a CSV file in ascending order by ```powershell Import-Csv C:\temp\sales-data.csv | - Sort-Object Date, @{expr={$_.UnitsSold}; desc=$true}, Salesperson | + Sort-Object Date, @{Expr={$_.UnitsSold}; Desc=$true}, Salesperson | Select-Object Date, Salesperson, UnitsSold ``` diff --git a/reference/7.6/CimCmdlets/Set-CimInstance.md b/reference/7.6/CimCmdlets/Set-CimInstance.md index ffb7ccd87334..0ec9fc79da15 100644 --- a/reference/7.6/CimCmdlets/Set-CimInstance.md +++ b/reference/7.6/CimCmdlets/Set-CimInstance.md @@ -236,9 +236,9 @@ Accept wildcard characters: False ### -Namespace -Specifies the namespace for the CIM operation. The default namespace is root/cimv2. You can use tab -completion to browse the list of namespaces, because PowerShell gets a list of namespaces from the -local WMI server to provide the list of namespaces. +Specifies the namespace for the CIM operation. The default namespace is **root/CIMV2**. You can use +tab completion to browse the list of namespaces, because PowerShell gets a list of namespaces from +the local WMI server to provide the list of namespaces. ```yaml Type: System.String @@ -362,11 +362,11 @@ A URI consists of a prefix and a path to a resource. For example: By default, if you do not specify this parameter, the DMTF standard resource URI `http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/` is used and the class name is appended to it. -ResourceURI can only be used with CIM sessions created using the WSMan protocol, or when specifying -the ComputerName parameter, which creates a CIM session using WSMan. If you specify this parameter -without specifying the ComputerName parameter, or if you specify a CIM session created using DCOM -protocol, you will get an error, because the DCOM protocol does not support the ResourceURI -parameter. +**ResourceUri** can only be used with CIM sessions created using the WSMan protocol, or when +specifying the **ComputerName** parameter, which creates a CIM session using WSMan. If you specify +this parameter without specifying the **ComputerName** parameter, or if you specify a CIM session +created using DCOM protocol, you will get an error, because the DCOM protocol does not support the +**ResourceUri** parameter. If both the **ResourceUri** parameter and the **Filter** parameter are specified, the **Filter** parameter is ignored. diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/About.md b/reference/7.6/Microsoft.PowerShell.Core/About/About.md index 31c17830509a..de8bee0e8fdb 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/About.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/About.md @@ -150,7 +150,7 @@ Describes the PowerShell debugger. ### [about_Do](about_Do.md) -Runs a statement list one or more times, subject to a `While` or `Until` +Runs a statement list one or more times, subject to a `while` or `until` condition. ### [about_Enum](about_Enum.md) @@ -268,8 +268,8 @@ expression in the background without interacting with the current session. ### [about_Join](about_Join.md) -Describes how the join operator (-join) combines multiple strings into a single -string. +Describes how the join operator (`-join`) combines multiple strings into a +single string. ### [about_Language_Keywords](about_Language_Keywords.md) @@ -398,8 +398,8 @@ Describes how to create and use a PowerShell profile. ### [about_Prompts](about_Prompts.md) -Describes the `Prompt` function and demonstrates how to create a custom -`Prompt` function. +Describes the `prompt` function and demonstrates how to create a custom +`prompt` function. ### [about_Properties](about_Properties.md) @@ -426,7 +426,7 @@ The automatic variable that contains the current object in the pipeline object. ### [about_PSModulePath](about_PSModulePath.md) -This article the purpose and usage of the `$env:PSModulePath` environment +This article the purpose and usage of the `$Env:PSModulePath` environment variable. ### [about_PSSession_Details](about_PSSession_Details.md) diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md index f0f2346e86bb..147f2ac9ac64 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_ANSI_Terminals.md @@ -3,7 +3,7 @@ description: Describes the features of PowerShell that use ANSI escape sequences Locale: en-US ms.date: 08/27/2024 schema: 2.0.0 -title: about_ANSI_terminals +title: about_ANSI_Terminals --- # about_ANSI_Terminals @@ -230,7 +230,7 @@ in the `bash` process, outside of the PowerShell host, the output isn't affected by **OutputRendering**. ```bash -pwsh -noprofile -command 'Get-ChildItem' > out.txt +pwsh -NoProfile -Command 'Get-ChildItem' > out.txt ``` When you inspect the contents of `out.txt` you see the ANSI escape sequences. @@ -239,7 +239,7 @@ By contrast, when redirection occurs within the PowerShell session, **OutputRendering** affects the redirected output. ```bash -pwsh -noprofile -command 'Get-ChildItem > out.txt' +pwsh -NoProfile -Command 'Get-ChildItem > out.txt' ``` When you inspect the contents of `out.txt` there are no ANSI escape sequences. @@ -249,13 +249,13 @@ When you inspect the contents of `out.txt` there are no ANSI escape sequences. Support for ANSI escape sequences can be turned off using the **TERM** or **NO_COLOR** environment variables. -The following values of `$env:TERM` change the behavior as follows: +The following values of `$Env:TERM` change the behavior as follows: - `dumb` - sets `$Host.UI.SupportsVirtualTerminal = $false` - `xterm-mono` - sets `$PSStyle.OutputRendering = PlainText` - `xterm` - sets `$PSStyle.OutputRendering = PlainText` -If `$env:NO_COLOR` exists, then `$PSStyle.OutputRendering` is set to +If `$Env:NO_COLOR` exists, then `$PSStyle.OutputRendering` is set to **PlainText**. For more information about the **NO_COLOR** environment variable, see [https://no-color.org/][04]. diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Alias_Provider.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Alias_Provider.md index 062f5be1eef4..afc7e87313f9 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Alias_Provider.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Alias_Provider.md @@ -149,7 +149,7 @@ current location is in the `Alias:` drive, the `-Path` parameter is not needed. This command also uses the `-Options` dynamic parameter to set the **AllScope** option on the alias. The `-Options` parameter is available in the `New-Item` cmdlet only when you are in the `Alias:` drive. The dot (`.`) indicates the -current directory, which is the alias drive. +current directory, which is the `Alias:` drive. ``` PS Alias:\> New-Item -Path . -Name serv -Value Get-Service -Options "AllScope" @@ -161,7 +161,7 @@ You can create an alias for any item that invokes a command. This command creates the `np` alias for `Notepad.exe`. ```powershell -New-Item -Path Alias:np -Value c:\windows\notepad.exe +New-Item -Path Alias:np -Value C:\windows\notepad.exe ``` ### Create an alias to a new function @@ -177,7 +177,7 @@ When the command is complete, you can use either `CD32` or `go` to invoke the function. ```powershell -function CD32 {Set-Location -Path c:\windows\system32} +function CD32 {Set-Location -Path C:\windows\system32} Set-Item -Path Alias:go -Value CD32 ``` @@ -313,7 +313,7 @@ Get-Help Get-ChildItem ``` ```powershell -Get-Help Get-ChildItem -Path alias: +Get-Help Get-ChildItem -Path Alias: ``` ## See also diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md index c5a74f24f094..4525b7caaef3 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md @@ -227,7 +227,7 @@ following example, the negative value can't be cast to an unsigned integer, and the unsigned integer is too large to be cast to `Int32`: ```powershell -([int32]::minvalue + [uint32]::maxvalue).GetType().FullName +([int32]::MinValue + [uint32]::MaxValue).GetType().FullName ``` ```Output @@ -241,10 +241,10 @@ The `System.Decimal` type is an exception. If either operand has the **Decimal** value is an error. ```powershell -PS> [Decimal]::maxvalue +PS> [decimal]::MaxValue 79228162514264337593543950335 -PS> [Decimal]::maxvalue + 1 +PS> [decimal]::MaxValue + 1 RuntimeException: Value was either too large or too small for a Decimal. ``` @@ -454,12 +454,12 @@ InvalidOperation: A hash table can only be added to another hash table. Although the addition operators are very useful, use the assignment operators to add elements to hash tables and arrays. For more information see -[about_assignment_operators](about_Assignment_Operators.md). The following +[about_Assignment_Operators](about_Assignment_Operators.md). The following examples use the `+=` assignment operator to add items to an array: ```powershell $array = @() -(0..2).foreach{ $array += $_ } +(0..2).ForEach{ $array += $_ } $array ``` @@ -497,7 +497,7 @@ The following examples show how to use the arithmetic operators in expressions with PowerShell commands: ```powershell -(Get-Date) + (New-TimeSpan -day 1) +(Get-Date) + (New-TimeSpan -Day 1) ``` The parenthesis operator forces the evaluation of the `Get-Date` cmdlet and the @@ -505,7 +505,7 @@ evaluation of the `New-TimeSpan -Day 1` cmdlet expression, in that order. Both results are then added using the `+` operator. ```powershell -Get-Process | Where-Object { ($_.ws * 2) -gt 50mb } +Get-Process | Where-Object { ($_.WS * 2) -gt 50mb } ``` ```Output @@ -519,7 +519,7 @@ Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName 967 30 58804 59496 416 930.97 2508 WINWORD ``` -In the above expression, each process working space (`$_.ws`) is multiplied by +In the above expression, each process working space (`$_.WS`) is multiplied by `2`; and, the result, compared against `50mb` to see if it's greater than that. ## Bitwise operators @@ -540,7 +540,7 @@ PowerShell supports the following bitwise operators. | `-band` | Bitwise AND | `10 -band 3` | 2 | | `-bor` | Bitwise OR (inclusive) | `10 -bor 3` | 11 | | `-bxor` | Bitwise OR (exclusive) | `10 -bxor 3` | 9 | -| `-bnot` | Bitwise NOT | `-bNot 10` | -11 | +| `-bnot` | Bitwise NOT | `-bnot 10` | -11 | | `-shl` | Shift-left | `102 -shl 2` | 408 | | `-shr` | Shift-right | `102 -shr 1` | 51 | @@ -587,7 +587,7 @@ For example, the binary complement of 0 is -1, the maximum unsigned integer (0xFFFFFFFF), and the binary complement of -1 is 0. ```powershell --bNot 10 +-bnot 10 ``` ```Output diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Arrays.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Arrays.md index 2b8392cf9e24..c78a22ac05ef 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Arrays.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Arrays.md @@ -305,7 +305,7 @@ value in an array, type: ```powershell $a = 0..9 -for ($i = 0; $i -le ($a.length - 1); $i += 2) { +for ($i = 0; $i -le ($a.Length - 1); $i += 2) { $a[$i] } ``` @@ -346,11 +346,11 @@ In PowerShell, arrays have three properties that indicate the number of items contained in the array. - **Count** - This property is the most commonly used property to determine the - number of items in any collection, not just an array. It's an `[Int32]` type + number of items in any collection, not just an array. It's an `[int32]` type value. In Windows PowerShell 5.1 (and older) **Count** alias property for **Length**. -- **Length** - This property is an `[Int32]` type value. This contains the same +- **Length** - This property is an `[int32]` type value. This contains the same value as **Count**. > [!NOTE] @@ -359,7 +359,7 @@ contained in the array. > string is the number of characters in the string. But the **Count** > property is always `1`. -- **Longlength** - This property is an `[Int64]` type value. Use this property +- **LongLength** - This property is an `[int64]` type value. Use this property for arrays containing more than 2,147,483,647 elements. ```powershell @@ -408,8 +408,8 @@ Multidimensional arrays are stored in [row-major order][14]. The following example shows how to create a truly multidimensional array. ```powershell -[string[,]]$rank2 = [string[,]]::New(3,2) -$rank2.rank +[string[,]]$rank2 = [string[,]]::new(3,2) +$rank2.Rank $rank2.Length $rank2[0,0] = 'a' $rank2[0,1] = 'b' @@ -487,7 +487,7 @@ True In this example, `$intA` is explicitly typed to contain integers. ```powershell -[Int[]] $intA = 1, 2, 3 +[int[]] $intA = 1, 2, 3 $intA.Clear() $intA ``` @@ -552,7 +552,7 @@ For more information about the behavior of **ArgumentList**, see The `ForEach()` method can be used to cast the elements to a different type; the following example shows how to convert a list of string dates to -`[DateTime]` type. +`[datetime]` type. ```powershell ("1/1/2017", "2/1/2017", "3/1/2017").ForEach([datetime]) @@ -680,7 +680,7 @@ to return. ```powershell # Get the zip files in the current users profile, sorted by LastAccessTime -$Zips = dir $env:userprofile -Recurse '*.zip' | Sort-Object LastAccessTime +$Zips = dir $Env:USERPROFILE -Recurse '*.zip' | Sort-Object LastAccessTime # Get the least accessed file over 100MB $Zips.Where({$_.Length -gt 100MB}, 'Default', 1) ``` @@ -876,7 +876,7 @@ create the `$t` array with all the elements in the `$a` array except for the value at index position 2, type: ```powershell -$t = $a[0,1 + 3..($a.length - 1)] +$t = $a[0,1 + 3..($a.Length - 1)] ``` To combine two arrays into a single array, use the plus operator (`+`). The @@ -1101,7 +1101,7 @@ LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;} ## See also - [about_For][05] -- [about_ForEach][06] +- [about_Foreach][06] - [about_Hash_Tables][07] - [about_Member-Access_Enumeration][09] - [about_Operators][11] @@ -1114,7 +1114,7 @@ LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;} [03]: about_Assignment_Operators.md [04]: about_Booleans.md [05]: about_For.md -[06]: about_ForEach.md +[06]: about_Foreach.md [07]: about_Hash_Tables.md [08]: about_Intrinsic_Members.md [09]: about_Member-Access_Enumeration.md diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md index eca6c6885348..57b337d02435 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Assignment_Operators.md @@ -82,7 +82,7 @@ pipeline to a variable. For example, the following command sorts the services on the computer and then assigns the sorted services to the `$a` variable: ```powershell -$a = Get-Service | Sort-Object -Property name +$a = Get-Service | Sort-Object -Property Name ``` You can also assign the value created by a statement to a variable, as in the diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md index 77579dd8b7ec..b88223cfd65e 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md @@ -211,8 +211,8 @@ non-zero integer. ### `$foreach` -Contains the enumerator (not the resulting values) of a [ForEach][56] loop. The -`$foreach` variable exists only while the `ForEach` loop is running; it's +Contains the enumerator (not the resulting values) of a [foreach][56] loop. The +`$foreach` variable exists only while the `foreach` loop is running; it's deleted after the loop is completed. Enumerators contain properties and methods you can use to retrieve loop values @@ -222,19 +222,19 @@ and change the current loop iteration. For more information, see ### `$HOME` Contains the full path of the user's home directory. On Windows, this variable -uses the value of the `"$env:USERPROFILE"` Windows environment variable, +uses the value of the `"$Env:USERPROFILE"` Windows environment variable, typically `C:\Users\`. On Unix, this variable uses the value of the `HOME` environment variable. > [!IMPORTANT] > Windows can redirect the location of the user's profile. This means that -> `$HOME` may not have the same value as `"$env:HOMEDRIVE$env:HOMEPATH"`. +> `$HOME` may not have the same value as `"$Env:HOMEDRIVE$Env:HOMEPATH"`. ### `$Host` Contains an object that represents the current host application for PowerShell. You can use this variable to represent the current host in commands or to -display or change the properties of the host, such as `$Host.version` or +display or change the properties of the host, such as `$Host.Version` or `$Host.CurrentCulture`, or `$Host.UI.RawUI.BackGroundColor = "Red"`. > [!NOTE] @@ -489,7 +489,7 @@ Test-Path $PROFILE Or, you can use it in a command to create a profile: ```powershell -New-Item -ItemType file -Path $PROFILE -Force +New-Item -ItemType File -Path $PROFILE -Force ``` You can use it in a command to open the profile in **notepad.exe**: @@ -679,8 +679,8 @@ Contains a stack trace for the most recent error. ### `$switch` -Contains the enumerator not the resulting values of a `Switch` statement. The -`$switch` variable exists only while the `Switch` statement is running; it's +Contains the enumerator not the resulting values of a `switch` statement. The +`$switch` variable exists only while the `switch` statement is running; it's deleted when the `switch` statement completes execution. For more information, see [about_Switch][71]. @@ -1133,7 +1133,7 @@ Default (Current): End [53]: about_CommonParameters.md [54]: about_comparison_operators.md [55]: about_Continue.md -[56]: about_ForEach.md +[56]: about_Foreach.md [57]: about_Functions_Advanced_Methods.md [58]: about_Functions_Advanced_Parameters.md [59]: about_Functions_Advanced.md diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Booleans.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Booleans.md index b84379334fd9..e2f5f79f3785 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Booleans.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Booleans.md @@ -91,7 +91,7 @@ Examples: # Empty collections PS> [bool]@() False -PS> [bool](Get-ChildItem | Where-Object Name -eq 'Non-existent-File.txt') +PS> [bool](Get-ChildItem | Where-Object Name -EQ 'Non-existent-File.txt') False # Single-element collections PS> $a = @(0) diff --git a/reference/7.6/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md b/reference/7.6/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md index 34eca8daadc4..385b74ba2946 100644 --- a/reference/7.6/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md +++ b/reference/7.6/Microsoft.PowerShell.Core/About/about_Calculated_Properties.md @@ -33,76 +33,76 @@ The following list itemizes the cmdlets that support calculated properties and the key-value pairs that each cmdlet supports. - `Compare-Object` - - `expression` + - `Expression` - `ConvertTo-Html` - - `name`/`label` - optional (added in PowerShell 6.x) - - `expression` - - `width` - optional - - `alignment` - optional + - `Name`/`Label` - optional (added in PowerShell 6.x) + - `Expression` + - `Width` - optional + - `Alignment` - optional - `Format-Custom` - - `expression` - - `depth` - optional + - `Expression` + - `Depth` - optional - `Format-List` - - `name`/`label` - optional - - `expression` - - `formatstring` - optional + - `Name`/`Label` - optional + - `Expression` + - `FormatString` - optional This same set of key-value pairs also apply to calculated property values passed to the **GroupBy** parameter for all `Format-*` cmdlets. - `Format-Table` - - `name`/`label` - optional - - `expression` - - `formatstring` - optional - - `width` - optional - - `alignment` - optional + - `Name`/`Label` - optional + - `Expression` + - `FormatString` - optional + - `Width` - optional + - `Alignment` - optional - `Format-Wide` - - `expression` - - `formatstring` - optional + - `Expression` + - `FormatString` - optional - `Group-Object` - - `expression` + - `Expression` - `Measure-Object` - Only supports a script block for the expression, not a hashtable. - Not supported in PowerShell 5.1 and older. - `Select-Object` - - `name`/`label` - optional - - `expression` + - `Name`/`Label` - optional + - `Expression` - `Sort-Object` - - `expression` - - `ascending`/`descending` - optional + - `Expression` + - `Ascending`/`Descending` - optional > [!NOTE] -> The value of the `expression` can be a script block instead of a +> The value of the `Expression` can be a script block instead of a > hashtable. For more information, see the [Notes][02] section. ## Hashtable key definitions -- `name`/`label` - Specifies the name of the property being created. You can - use `name` or its alias, `label`, interchangeably. -- `expression` - A string or script block used to calculate the value of the - new property. If the `expression` is a string, the value is interpreted as a +- `Name`/`Label` - Specifies the name of the property being created. You can + use `Name` or its alias, `Label`, interchangeably. +- `Expression` - A string or script block used to calculate the value of the + new property. If the `Expression` is a string, the value is interpreted as a property name on the input object. This is a shorter option than - `expression = { $_. }`. -- `alignment` - Used by cmdlets that produce tabular output to define how the - values are displayed in a column. The value must be `'left'`, `'center'`, or - `'right'`. -- `formatstring` - Specifies a format string that defines how the value is + `Expression = { $_. }`. +- `Alignment` - Used by cmdlets that produce tabular output to define how the + values are displayed in a column. The value must be `'Left'`, `'Center'`, or + `'Right'`. +- `FormatString` - Specifies a format string that defines how the value is formatted for output. For more information about format strings, see [Format types in .NET][01]. -- `width` - Specifies the maximum width column in a table when the value is +- `Width` - Specifies the maximum width column in a table when the value is displayed. The value must be greater than `0`. -- `depth` - The **Depth** parameter of `Format-Custom` specifies the depth of - expansion for all properties. The `depth` key allows you to specify the +- `Depth` - The **Depth** parameter of `Format-Custom` specifies the depth of + expansion for all properties. The `Depth` key allows you to specify the depth of expansion per property. -- `ascending` / `descending` - Allows you to specify the order of sorting for +- `Ascending` / `Descending` - Allows you to specify the order of sorting for one or more properties. These are boolean values. You don't need to spell out the hashtable keys as long as the specified name @@ -119,7 +119,7 @@ directly, the values are compared to the result of the arithmetic operation (modulus of 2). ```powershell -Compare-Object @{p=1} @{p=2} -property @{ Expression = { $_.p % 2 } } +Compare-Object @{p=1} @{p=2} -Property @{ Expression = { $_.p % 2 } } ``` ```Output @@ -139,9 +139,9 @@ Get-Alias | ConvertTo-Html Name, Definition, @{ - name='ParameterCount' - expr={$_.Parameters.Keys.Count} - align='center' + Name='ParameterCount' + Expr={$_.Parameters.Keys.Count} + Align='Center' } | Out-File .\aliases.htm -Force ``` @@ -155,15 +155,15 @@ the number parameters for each aliased command. The values of `Format-Custom` provides a custom view of an object in a format similar to a class definition. More complex objects can contain members that are deeply nested with complex types. The **Depth** parameter of `Format-Custom` specifies -the depth of expansion for all properties. The `depth` key allows you to +the depth of expansion for all properties. The `Depth` key allows you to specify the depth of expansion per property. -In this example, the `depth` key simplifies the custom output for the +In this example, the `Depth` key simplifies the custom output for the `Get-Date` cmdlet. `Get-Date` returns a **DateTime** object. The **Date** property of this object is also a **DateTime** object, so the object is nested. ```powershell -Get-Date | Format-Custom @{expr={$_.Date};depth=1},TimeOfDay +Get-Date | Format-Custom @{Expr={$_.Date};Depth=1},TimeOfDay ``` ```Output @@ -212,16 +212,16 @@ the output from `Get-ChildItem`. ```powershell Get-ChildItem *.json -File | - Format-List Fullname, + Format-List FullName, @{ - name='Modified' - expression={$_.LastWriteTime} - formatstring='O' + Name='Modified' + Expression={$_.LastWriteTime} + FormatString='O' }, @{ - name='Size' - expression={$_.Length/1KB} - formatstring='N2' + Name='Size' + Expression={$_.Length/1KB} + FormatString='N2' } ``` @@ -246,11 +246,11 @@ classify the files by the content type. ```powershell Get-ChildItem -File | - Sort-Object extension | + Sort-Object Extension | Format-Table Name, Length -GroupBy @{ - name='Type' - expression={ - switch ($_.extension) { + Name='Type' + Expression={ + switch ($_.Extension) { '.md' {'Content'} '' {'Metacontent'} '.ps1' {'Automation'} @@ -312,7 +312,7 @@ value. ```powershell Get-ChildItem -File | - Format-Wide -Property @{e={'{0} ({1:N2}kb)' -f $_.name,($_.length/1kb)}} + Format-Wide -Property @{e={'{0} ({1:N2}kb)' -f $_.Name,($_.Length/1kb)}} ``` ```Output @@ -335,10 +335,10 @@ of files of each content type. ```powershell Get-ChildItem -File | - Sort-Object extension | + Sort-Object Extension | Group-Object -NoElement -Property @{ - expression={ - switch ($_.extension) { + Expression={ + switch ($_.Extension) { '.md' {'Content'} '' {'Metacontent'} '.ps1' {'Automation'} @@ -400,8 +400,8 @@ $aliases = Get-Alias c* | Select-Object Name, Definition, @{ - name='ParameterCount' - expr={$_.Parameters.Keys.Count} + Name='ParameterCount' + Expr={$_.Parameters.Keys.Count} } $aliases | Get-Member $aliases @@ -451,7 +451,7 @@ property. This example sorts data from a CSV file in ascending order by ```powershell Import-Csv C:\temp\sales-data.csv | - Sort-Object Date, @{expr={$_.UnitsSold}; desc=$true}, Salesperson | + Sort-Object Date, @{Expr={$_.UnitsSold}; Desc=$true}, Salesperson | Select-Object Date, Salesperson, UnitsSold ```