11---
2- ms.date : 2017-06-09
2+ ms.date : 2017-12-05
33schema : 2.0.0
44locale : en-us
55keywords : powershell,cmdlet
@@ -248,7 +248,7 @@ debug message is not displayed and processing continues. The final command
248248uses the Debug parameter to override the preference for a single command.
249249
250250``` powershell
251- PS> $debugpreference # Get the current value of \ $DebugPreference
251+ PS> $debugpreference # Get the current value of $DebugPreference
252252SilentlyContinue
253253
254254PS> write-debug "Hello, World"
@@ -301,7 +301,7 @@ uses the Debug parameter with a value of \$false to suppress the message for
301301a single command.
302302
303303``` powershell
304- PS> \ $debugpreference = "Inquire"
304+ PS> $debugpreference = "Inquire"
305305PS> write-debug "Hello, World"
306306DEBUG: Hello, World
307307
@@ -393,14 +393,14 @@ a non-existent file, nofile.txt. The example also uses the ErrorAction common
393393parameter to override the preference.
394394
395395``` powershell
396- PS> \ $erroractionpreference
396+ PS> $erroractionpreference
397397SilentlyContinue # Display the value of the preference.
398398
399399PS> get-childitem -path nofile.txt
400400PS> # Error message is suppressed.
401401
402402PS> # Change the value to Continue.
403- PS> \ $ErrorActionPreference = "Continue"
403+ PS> $ErrorActionPreference = "Continue"
404404
405405PS> get-childitem -path nofile.txt
406406Get-ChildItem : Cannot find path 'C:\nofile.txt' because it does not exist.
@@ -412,7 +412,7 @@ PS> get-childitem -path nofile.txt -erroraction SilentlyContinue
412412PS> # Error message is suppressed.
413413
414414PS> # Change the value to Inquire.
415- PS> \ $ErrorActionPreference = "Inquire"
415+ PS> $ErrorActionPreference = "Inquire"
416416PS> get-childitem -path nofile.txt
417417
418418Confirm
@@ -425,7 +425,7 @@ At line:1 char:4
425425+ get-childitem <<<< nofile.txt
426426
427427PS> # Change the value to Continue.
428- PS> \ $ErrorActionPreference = "Continue"
428+ PS> $ErrorActionPreference = "Continue"
429429PS> Get-Childitem nofile.txt -erroraction "Inquire"
430430PS> # Use the ErrorAction parameter to override the preference value.
431431
@@ -462,7 +462,7 @@ NormalView. In this case, the Get-ChildItem command is used to find a
462462non-existent file.
463463
464464``` powershell
465- PS> \ $ErrorView # Verify the value.
465+ PS> $ErrorView # Verify the value.
466466NormalView
467467
468468PS> get-childitem nofile.txt # Find a non-existent file.
@@ -475,7 +475,7 @@ This example shows how the same error appears when the value of
475475\$ ErrorView is CategoryView.
476476
477477``` powershell
478- PS> \ $ErrorView = "CategoryView" # Change the value to
478+ PS> $ErrorView = "CategoryView" # Change the value to
479479CategoryView
480480
481481PS> get-childitem nofile.txt
@@ -493,7 +493,7 @@ error in the error array (element 0) and formats all of the properties of the
493493error object in a list.
494494
495495``` powershell
496- PS> \ $error[0] | format-list -property * -force
496+ PS> $error[0] | format-list -property * -force
497497
498498Exception : System.Management.Automation.ItemNotFoundException: Cannot
499499find path 'C:\nofile.txt' because it does not exist.
@@ -546,10 +546,10 @@ In the resulting display, the list in the Group column is now limited by the
546546line length. In the final command in the example, use the Wrap parameter of
547547Format-Table to display all of the processes in each Status group.
548548
549- PS> \$ formatenumerationlimit # Find the current value
549+ ``` powershell
550+ PS> $formatenumerationlimit # Find the current value
5505514
551552
552- ``` powershell
553553PS> # List all services grouped by status
554554PS> get-service | group-object -property status
555555
@@ -560,7 +560,7 @@ Count Name Group
560560PS> # The list is truncated after 4 items.
561561
562562PS> # Increase the limit to 1000.
563- PS> \ $formatenumerationlimit = 1000
563+ PS> $formatenumerationlimit = 1000
564564PS> get-service | group-object -property status
565565
566566Count Name Group
@@ -650,20 +650,20 @@ The Log*Event preference variables are as follows:
650650To enable a Log* Event, type the variable with a value of \$ true, for example:
651651
652652``` powershell
653- \ $LogCommandLifeCycleEvent
653+ $LogCommandLifeCycleEvent
654654```
655655
656656- or -
657657
658658``` powershell
659- \ $LogCommandLifeCycleEvent = \ $true
659+ $LogCommandLifeCycleEvent = $true
660660```
661661
662662To disable an event type, type the variable with a value of \$ false, for
663663example:
664664
665665``` powershell
666- \ $LogCommandLifeCycleEvent = \ $false
666+ $LogCommandLifeCycleEvent = $false
667667```
668668
669669The events that you enable are effective only for the current PowerShell
@@ -719,26 +719,26 @@ To count the errors on your system, use the Count property of the \$Error
719719array. Type:
720720
721721``` powershell
722- \ $Error.count
722+ $Error.count
723723```
724724
725725To display a specific error, use array notation to display the error. For
726726example, to see the most recent error, type:
727727
728728``` powershell
729- \ $Error[0]
729+ $Error[0]
730730```
731731
732732To display the oldest retained error, type:
733733
734734``` powershell
735- \ $Error[(\ $Error.Count -1]
735+ $Error[($Error.Count -1]
736736```
737737
738738To display the properties of the ErrorRecord object, type:
739739
740740``` powershell
741- \ $Error[0] | format-list -property * -force
741+ $Error[0] | format-list -property * -force
742742```
743743
744744In this command, the Force parameter overrides the special formatting of
@@ -748,11 +748,11 @@ To delete all errors from the error history, use the Clear method of the error
748748array.
749749
750750``` powershell
751- PS> \ $Error.count
751+ PS> $Error.count
75275217
753- PS> \ $Error.clear()
753+ PS> $Error.clear()
754754PS>
755- PS> \ $Error.count
755+ PS> $Error.count
7567560
757757```
758758
@@ -844,19 +844,19 @@ is converted to a string. In this case, an array of integers is stored in a
844844variable and then the variable is cast as a string.
845845
846846``` powershell
847- PS> \ $array = 1,2,3 # Store an array of integers.
847+ PS> $array = 1,2,3 # Store an array of integers.
848848
849- PS> [string]\ $array # Cast the array to a string.
849+ PS> [string]$array # Cast the array to a string.
8508501 2 3 # Spaces separate the elements
851851```
852852
853853To change the separator, add the \$ OFS variable by assigning a value to it.
854854To work correctly, the variable must be named \$ OFS.
855855
856856``` powershell
857- PS> \ $OFS = "+" # Create \$OFS and assign a "+"
857+ PS> $OFS = "+" # Create \$OFS and assign a "+"
858858
859- PS> [string]\ $array # Repeat the command
859+ PS> [string]$array # Repeat the command
8608601+2+3 # Plus signs separate the elements
861861```
862862
@@ -868,7 +868,7 @@ verifies that the separator is a space.
868868PS> Remove-Variable OFS # Delete \$OFS
869869PS>
870870
871- PS> [string]\ $array # Repeat the command
871+ PS> [string]$array # Repeat the command
8728721 2 3 # Spaces separate the elements
873873```
874874
@@ -897,7 +897,7 @@ The first command finds the value of \$OutputEncoding. Because the value is an
897897encoding object, display only its EncodingName property.
898898
899899``` powershell
900- PS> \ $OutputEncoding.EncodingName # Find the current value US-ASCII
900+ PS> $OutputEncoding.EncodingName # Find the current value US-ASCII
901901```
902902
903903In this example, a FINDSTR command is used to search for two Chinese
@@ -918,9 +918,9 @@ locale selected for Windows. Because OutputEncoding is a static property of
918918the console, use double-colons (::) in the command.
919919
920920``` powershell
921- PS> \ $OutputEncoding = [console]::outputencoding
921+ PS> $OutputEncoding = [console]::outputencoding
922922PS> # Set the value equal to the OutputEncoding property of the console.
923- PS> \ $OutputEncoding.EncodingName
923+ PS> $OutputEncoding.EncodingName
924924OEM United States
925925```
926926As a result of this change, the FINDSTR command finds the characters.
@@ -1100,7 +1100,7 @@ values you prefer. Save the output in a variable called \$PSSessionOption.
11001100For example,
11011101
11021102``` powershell
1103- \ $PSSessionOption = New-PSSessionOption -NoCompression
1103+ $PSSessionOption = New-PSSessionOption -NoCompression
11041104```
11051105
11061106To use the \$ PSSessionOption preference variable in every PowerShell session,
@@ -1202,7 +1202,7 @@ This example shows the effect of the Inquire value.
12021202
12031203``` powershell
12041204PS> # Change the value to Inquire.
1205- PS> \ $VerbosePreference = "Inquire"
1205+ PS> $VerbosePreference = "Inquire"
12061206PS> Write-Verbose "Verbose message test."
12071207VERBOSE: Verbose message test.
12081208Confirm
@@ -1249,7 +1249,7 @@ value.
12491249This example shows the effect of the Continue value, which is the default.
12501250
12511251``` powershell
1252- PS> \ $WarningPreference # Find the current value.
1252+ PS> $WarningPreference # Find the current value.
12531253Continue
12541254PS> Write-Warning "This action can delete data."
12551255WARNING: This action can delete data.
@@ -1263,7 +1263,7 @@ This example shows the effect of the SilentlyContinue value.
12631263
12641264``` powershell
12651265PS> # Change the value to SilentlyContinue.
1266- PS> \ $WarningPreference = "SilentlyContinue"
1266+ PS> $WarningPreference = "SilentlyContinue"
12671267PS> Write-Warning "This action can delete data."
12681268PS> # Write a warning message.
12691269
@@ -1280,7 +1280,7 @@ This example shows the effect of the Inquire value.
12801280
12811281``` powershell
12821282PS> # Change the value to Inquire.
1283- PS> \ $WarningPreference = "Inquire"
1283+ PS> $WarningPreference = "Inquire"
12841284PS> Write-Warning "This action can delete data."
12851285WARNING: This action can delete data.
12861286
@@ -1299,7 +1299,7 @@ This example shows the effect of the Stop value.
12991299
13001300``` powershell
13011301PS> # Change the value to Stop.
1302- PS> \ $WarningPreference = "Stop"
1302+ PS> $WarningPreference = "Stop"
13031303
13041304PS> Write-Warning "This action can delete data."
13051305WARNING: This action can delete data.
@@ -1360,7 +1360,7 @@ This example shows the effect of the 0 (not enabled) value, which is the
13601360default.
13611361
13621362``` powershell
1363- PS> \ $whatifpreference
1363+ PS> $whatifpreference
136413640 # Check the current value.
13651365
13661366PS> # Verify that the file exists.
@@ -1400,8 +1400,8 @@ Remove-Item to delete a cmdlet, Remove-Item displays the path to the file that
14001400it would delete, but it does not delete the file.
14011401
14021402``` powershell
1403- PS> \ $whatifpreference = 1
1404- PS> \ $whatifpreference
1403+ PS> $whatifpreference = 1
1404+ PS> $whatifpreference
140514051 # Change the value.
14061406
14071407PS> # Try to delete a file.
@@ -1430,7 +1430,7 @@ a value of \$false.
14301430
14311431``` powershell
14321432PS> # Change the value to 1.
1433- PS> \ $whatifpreference = 1
1433+ PS> $whatifpreference = 1
14341434
14351435PS> get-process winword
14361436A Get-Process command completes.
0 commit comments