- Powershell Core 6.2 Cookbook
- Jan Hendrik Peters
- 124字
- 2021-06-24 15:14:24
How to do it...
Install and start PowerShell Core and execute the following steps:
- Try to execute the following code block:
$true = $false
$pid = 0
$Error = "I don't make mistakes!"
- Execute the next cmdlet to see why Step 1 didn't work as intended:
Get-Variable | Where-Object -Property Options -like *Constant*
- You can create your own read-only and constant variables using variable cmdlets:
# Creating read-only and constants requires the variable cmdlets
$logPath = 'D:\Logs'
Set-Variable -Name logPath -Option ReadOnly
- Modifying read-only variables is still possible with the -Force parameter:
Set-Variable -Name logPath -Value '/var/log' -Force
- The Option parameter is useful for other purposes as well, such as creating private and global variables:
Get-Help -Name New-Variable -Parameter Option