PowerShell - Variables

PowerShell - Variables

# variables are limited to Scope in which they are created

$Console_Ctreated = 1

Invoke-Command -ScriptBlock {$Script_Created =5;$Script_Created}

Invoke-Command -ScriptBlock {$Global:Script_Created =5;$Script_Created}

$Console_Ctreated

$Script_Created


# Data declaration requirement for Variables

[int]$NumberOne = Read-Host "Write First Number"

[int]$NumberTwo = Read-Host "Write Second Number"

$AdditionOfNumber = $NumberOne +$NumberTwo

$AdditionOfNumber

# Double and Single Quotation Marks

$Test_Var = 2

Write-host "The Value of Variable is $Test_Var"

Write-host 'The Value of Variable is $Test_var'

# Automatic Variables
$$
$?
$_
$PID
$PsCulture
$PWD

1..8|foreach{Write-Host $_}

# Preference variable
$MaximumHistoryCount
$MaximumHistoryCount = 10
posted @ 2022-01-04 17:44  晨风_Eric  阅读(35)  评论(0编辑  收藏  举报