Powershell Core 6.2 Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

Please perform the following steps:

  1. Review the output of Get-Command -Verb New,Set,Remove,Register,Unregister,Start,Stop to review some of the more frequently used cmdlets.
  2. Execute $file = New-TemporaryFile to create a temporary file.
  3. Use 'SomeContent' | Set-Content -Path $file to change the file contents.
  4. Use 'More content!' | Add-Content -Path $file to append data to the file.
  5. Review the contents with $file | Get-Item | Get-Content -Path.
  6. Lastly use $file | Remove-Item -Verbose to get rid of the file again.
  7. Use $ping = Start-Process -FilePath ping -ArgumentList 'packtpub.com' -PassThru.
  8. Use $ping | Stop-Process -PassThru to stop the background process.
  1. Use Start-Job -Name Sleepy { Start-Sleep -Seconds 100; Get-Date}.
  2. Have a look at the job with Get-Job -Name Sleepy—is it ready to deliver the data?
  3. Use Get-Job -Name Sleepy | Wait-Job to wait for the results.
  4. Lastly, use Get-Job -Name Sleepy | Receive-Job -Keep to gather the results.
  5. As an alternative, try $job = Get-ChildItem -Recurse -Force -Path $home & and $job | Wait-Job | Receive-Job.
  6. Clean up any remaining jobs by closing PowerShell or executing $job | Remove-Job; Get-Job -Name Sleepy | Remove-Job.