The following example writes all the values of an array, skipping any value that is less than zero. PowerShell Copy do { if ($x[$a] -lt 0) { continue } Write-Host $x[$a] } while (++$a -lt 10) See also about_Booleans about_Break about_Continue about_Operators about_Assignm...
在此範例中,腳本會建立五個ScopeExample.ps1函式。 第一個函式會呼叫下一個函式,這會建立子範圍。 其中一個函式具有私用變數,只能在建立它的範圍中看到。 PowerShell PS>Get-ContentScopeExample.ps1# Start of ScopeExample.ps1functionfuncA {"Setting `$funcAVar1 to 'Value set in funcA'"$funcAVar1...
PowerShell复制 $Env:Foo='An example' 由于环境变量始终是字符串,因此可以像使用包含字符串的任何其他变量一样使用它们。 例如: PowerShell复制 "The 'Foo' environment variable is set to:$Env:Foo"$Env:Foo+='!'$Env:Foo Output复制 The 'Foo' environment variable is set to: An example An example!
In the following example, only the Get-MrPSVersion function is exposed to users of your module, while the Get-MrComputerName function remains accessible internally to other functions within the module. PowerShell 複製 function Get-MrPSVersion { $PSVersionTable } function Get-MrComputerName { ...
While this would be OK, I want to demonstrate something better, so I will provide the key and the value.When I was first learning about IsolatedStorage, I noticed that it's pretty tough to find the actual file being used for the storage, so I want to include that information in my ...
Example 6: Invoke a command using a positional string as input PowerShell Copy Set-Location "SQLSERVER:\SQL\MyComputer\MainInstance\Databases\MyDatabase" PS SQLSERVER:\SQL\MyComputer\MainInstance> Invoke-Sqlcmd "SELECT DB_NAME() AS DatabaseName" WARNING: Using provider context. Server = MyCo...
Of course, learning about all of these capabilities will take a while, but you should find them easy to pick up through examples. Windows PowerShell itself helps to simplify learning. For example, if you type $c = $c. (don't forget the period mark) and press Tab, Windows PowerShell ...
While the PowerShell team introduced support for ANSI colors, they did not include any new cmdlets to configure the colors. You adjust the $PSStyle variable to change the colors. The variable has 26 color values. The $PSStyle automatic variable shows the properties for the text colo...
This example uses the Debug parameter with a value of $false to suppress the message for a single command. The debug message isn't displayed. PowerShell Copy Write-Debug -Message "Hello, World" -Debug:$false This example shows the effect of $DebugPreference being set to the Stop ...
while ($i -eq 0) { ## Do something > } Thedoloop is similar to thewhileloop. The only difference is PowerShell executes thedoloop at the end of the loop. do { ## do something } while ($i -lt 0) When you use aforeachloop, PowerShell repeats the code for each item mentioned...