如何使用 PowerShell 對映網路驅動器?


可以使用多種方法在本地和遠端計算機上對映網路驅動器。

  • 使用 cmd 命令。

可以使用以下命令在本地計算機上對映網路驅動器(在此處為字母 M)和共享資料夾。

示例

net use M: "\remoteshare\Shared Folder"

PS C:\WINDOWS\system32> net use M:
Local name        M:
Remote name       \remoteshare\Shared Folder
Resource type     Disk
Status            OK
# Opens           1
# Connections     1
The command completed successfully.

在遠端計算機上對映。

Invoke-Command -ComputerName RemoteComputer -ScriptBlock{net use k: "\remoteshare\shared"}
  • 使用 New-PSDrive 命令。

可以使用 PowerShell 命令 New-PSDrive 在本地和遠端計算機上對映網路驅動器。

在本地計算機上對映驅動器。

New-PSDrive -Name K -PSProvider FileSystem -Root \remoteshare\shared -Persist

輸出

PS C:\WINDOWS\system32> Get-PSDrive -Name K

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
K                 318.16         47.24 FileSystem    \remoteshare\shared

在遠端計算機上對映驅動器。

Invoke-Command -ComputerName Remotecomputer -ScriptBlock {New-PSDrive -Name K -PSProvider FileSystem -Root \remoteshare\shared -Persist}

更新於: 11-11-2020

4K+ 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告