A provider is an adapter that makes a data store look like a PowerShell drive. The FileSystem provider exposes files and folders through drives such as /, and generic item cmdlets manage what the drive contains. section 5.1
PS C:\Scripts\ > Get-PSProvider
Name Capabilities Drives
---- ------------ ------
Alias ShouldProcess {Alias}
Environment ShouldProcess {Env}
FileSystem Filter, ShouldProcess, Credentials {/}
Function ShouldProcess {Function}
Variable ShouldProcess {Variable}
Inspect installed providers with Get-PSProvider. The FileSystem provider advertises Filter, ShouldProcess, and Credentials capabilities, while other providers expose different operations. section 5.1
Work with a FileSystem provider by combining locations, paths, and item cmdlets:
- Use Set-Location, or its cd alias, to move to a folder. Windows can use paths such as C:\Users\name; Linux and macOS use a single root such as /. section 5.3
- Use Get-ChildItem to list contents, and use Item verbs such as New, Copy, Move, Remove, Rename, and Set to manage files and folders. section 5.1 section 5.2
- Specify -Path for wildcard matching, where * matches zero or more characters and ? matches one character; use -LiteralPath when those characters belong to the name. section 5.4
- Tell New-Item what to create: New-Item testFolder -ItemType Directory creates a directory, while a generic command may prompt because the item type is unknown. section 5.3
Create and inspect a directory
New-Item -Path ~/Labs -ItemType Directory Set-Location ~/Labs New-Item -Name Test.txt -ItemType File Get-ChildItem These commands create a directory, create a zero-length file, change location, and list the resulting filesystem items. section 5.6 section 5.7
Generic cmdlets do not guarantee that every provider supports every operation. The FileSystem provider lacks Transactions support, and Set-Item cannot change a file's contents; item properties and provider capabilities determine what is valid. section 5.2 section 5.7
