(PowerShell)New-PSDrive

Syntax

1
2
3
4
5
6
7
8
9
10
11
New-PSDrive
[-Name] <String>
[-PSProvider] <String>
[-Root] <String>
[-Description <String>]
[-Scope <String>]
[-Persist]
[-Credential <PSCredential>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]

Ex: 建立映射到網路共享的暫存磁碟

1
2
3
4
5
6
7
8
9
10
11
# 建立名為Public的暫存磁碟,映射到\\Server01\Public
New-PSDrive -Name "Public" -PSProvider "FileSystem" -Root "\\Server01\Public"

# 建立暫存磁碟後,可透過Get-Item或Get-ChildItem取得內容, 磁碟名稱後的冒號(:)記得一定要加
Get-ChildItem Public:
Get-Item Public:

# 新增/搬移/複製/刪除暫存磁碟檔案或目錄
Move-Item "xxx.txt" -Destination "Public:"
Copy-Item "xxx.txt" -Destination "Public:\AA
New-Item "Public:\LogArchive" -ItemType "Directory"