Clear-Variable [-Name] <String[]> [-Include <String[]>] [-Exclude <String[]>] [-Force] [-PassThru] [-Scope <String>] [-WhatIf] [-Confirm] [<CommonParameters>]说明Clear-Variable cmdlet 删除存储在变量中的数据,但不会删除该变量。 因此,变量的值为 NULL(空)。 如果变量具有指...
Get... Get-WmiObject Cmdlet Microsoft.PowerShell.M... Get... Start-Process Cmdlet Microsoft.PowerShell.M... Sta... Stop-Process Cmdlet Microsoft.PowerShell.M... Sto... Wait-Process Cmdlet Microsoft.PowerShell.M... Wai... Clear-Variable Cmdlet Microsoft.PowerShell.U... Del... Convert...
1. 使用Remove-Variable命令: Remove-Variable -Name 变量名 该命令会删除指定变量的值和名称。 2. 使用Clear-Variable命令: Clear-Variable -Name 变量名 该命令会清除指定变量的值,但保留变量的名称。 3. 使用Set-Variable命令赋予变量一个空值: Set-Variable -Name 变量名 -Value $null 该命令将指定变量的值...
Clear-Variable -Name MyVariable PowerShell 複製 $MyVariable = $null 若要刪除變數,請使用 Remove-Variable 或Remove-Item。 PowerShell 複製 Remove-Variable -Name MyVariable PowerShell 複製 Remove-Item -Path Variable:\MyVariable 您也可以使用一個語句,將值指派給多個變數。下列範例會將相同的...
$Env:<variable-name> = "<new-value>" 例如,若要建立 Foo 環境變數: PowerShell 複製 $Env:Foo = 'An example' 因為環境變數一律是字串,所以您可以使用它們,就像包含字元串的任何其他變數一樣。 例如: PowerShell 複製 "The 'Foo' environment variable is set to: $Env:Foo" $Env:Foo +...
Windows PowerShell reserves a few parameter names, referred to as Common parameters, which you can't use: WhatIf, Confirm, Verbose, Debug, ErrorAction, ErrorVariable, OutVariable, and OutBuffer. In addition, the following aliases for these parameter names are reserved: vb, db, ea, ev, ov...
Clear-History Deletes entries from the command history. Clear-Item Deletes the contents of an item but does not delete the item. Clear-ItemProperty Deletes the value of a property but does not delete the property. Clear-Variable Deletes the value of a variable. Compare-Object Compares two ...
Clear-Item Deletes the contents of an item, but does not delete the item. clp Clear-ItemProperty Deletes the value of a property but does not delete the property. cls Clear-Host Clears the display in the host program. clv Clear-Variable Deletes the value of a variable. cnsn...
I prefer that variable names be capitalized and be as descriptive as possible. Provide logical spacing in between your code. Indent your code to make it more readable. If you find yourself repeating code, write a function. Catch all anticipated errors and provide meaningful output. If you have...
Use clear and intelligently named variables Too often I come across scripts that use variables, for example,$j. This name has nothing to do with what the variable is going to be used for, and it doesn’t help distinguish its purpose later in the script from another variable,...