- Powershell Core 6.2 Cookbook
- Jan Hendrik Peters
- 128字
- 2021-06-24 15:14:26
How to do it...
Install and start PowerShell Core and execute the following steps:
- All streams can be redirected, thereby creating a new file, as in the following example:
Get-Item -Path $home,'nonexistant' 2> error.txt 1> success.txt
Get-Content -Path error.txt, success.txt
- You can also append different streams to files by using the >> operator:
Get-Item -Path $home,'nonexistant' 2>> error.txt 1>> success.txt
Get-Content -Path error.txt, success.txt
- Streams can also be combined into the output by using the >&1 operator:
# This helps e.g. with misbehaving external applications
Get-Module -Verbose -List -Name 'PackageManagement','nonexistant' 2>&1 4>&1
- Combining streams into the output will pollute the output, however:
$modules = Get-Module -Verbose -List -Name 'PackageManagement','nonexistant' 2>&1 4>&1
$modules.Count # This should contain only one...
$modules[0] # This definitely doesn't look like a module