將目前工作位置設定為指定的位置。

語法

Set-Location [-LiteralPath] <string> [-PassThru] [-UseTransaction] [<CommonParameters>]

Set-Location [[-Path] <string>] [-PassThru] [-UseTransaction] [<CommonParameters>]

Set-Location [-StackName <string>] [-PassThru] [-UseTransaction] [<CommonParameters>]

描述

Set-Location Cmdlet 會將工作位置設定為指定的位置。該指定位置可以是目錄、子目錄、登錄位置,或是其他的位置堆疊。

參數

-LiteralPath <string>

指定位置的路徑。LiteralPath 會使用實際輸入的內容做為參數值。任何字元均不被解譯成萬用字元。如果路徑中包含逸出字元,請將其置於單引號內。單引號係告訴 Windows PowerShell 不要將任何字元解譯成逸出序列。

必要?

true

位置?

1

預設值

接受管線輸入?

true (ByPropertyName)

接受萬用字元?

false

-PassThru

會將代表位置的物件傳遞給管線。根據預設,此 Cmdlet 不會產生任何輸出。

必要?

false

位置?

named

預設值

接受管線輸入?

false

接受萬用字元?

false

-Path <string>

此參數用於指定新工作位置的路徑。

必要?

false

位置?

1

預設值

接受管線輸入?

true (ByValue, ByPropertyName)

接受萬用字元?

false

-StackName <string>

要設定位置的堆疊名稱。

必要?

false

位置?

named

預設值

接受管線輸入?

true (ByPropertyName)

接受萬用字元?

false

-UseTransaction

將命令加入現用交易中。此參數只有當交易進行中時才有效。如需詳細資訊,請參閱 about_Transactions。

必要?

false

位置?

named

預設值

接受管線輸入?

false

接受萬用字元?

false

<CommonParameters>

這個 Cmdlet 支援一般參數:-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer 和 -OutVariable。如需詳細資訊,請參閱 about_Commonparameters.

輸入和輸出

輸入型別是可經由管道輸出至 Cmdlet 的物件型別。傳回型別則是 Cmdlet 所傳回的物件型別。

輸入

System.String

您可經由管道將包含路徑 (但不是常值路徑) 的字串輸出至 Set-Location。

輸出

None 或 System.Management.Automation.PathInfo

當您使用 PassThru 參數時,Set-Location 會產生代表位置的 System.Management.Automation.PathInfo 物件,否則,這個 Cmdlet 不會產生任何輸出。

附註

Set-Location Cmdlet 設計的用意是要操作任一提供者所公開的資料。若要列出可在工作階段中使用的提供者,請輸入 "Get-PSProvider"。如需詳細資訊,請參閱 about_Providers。

範例 1

C:\PS>set-location HKLM:

描述
-----------
這個命令會將目前位置設定為指定的位置,在這個範例中是指 HKLM 提供者。






範例 2

C:\PS>set-location env: -passthru

Path
----
Env:\

描述
-----------
這個命令會將目前位置設定為指定的位置,在這個範例中是指環境變數提供者。






範例 3

C:\PS>set-location C:

描述
-----------
這個命令會將目前位置設定為指定的位置,在這個範例中是指檔案系統提供者中的 C: 磁碟機。






請參閱




目錄