《Learn Windows PowerShell in a Month of Lunches Third Edition》读书笔记——CHAPTER 5 Working with providers

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_41104353/article/details/82181274

5.1 What are providers?

我们可以使用 Get-PSProvider 命令来查看PowerShell的providers

每个provider有不同的功能,比如:

ShouldProcess—The provider supports the use of the -WhatIf and -Confirm parameters, enabling you to “test” certain actions before committing to them.
Filter—The provider supports the -Filter parameter on the cmdlets that manipulate providers’ content.
Credentials—The provider permits you to specify alternate credentials when connecting to data stores. There’s a -credential parameter for this.
Transactions—The provider supports the use of transactions, which allows you to use the provider to make several changes, and then either roll back or commit those changes as a single unit.

我们可以使用一个provider来创建一个PSDrive。
A PSDrive uses a single provider to connect to data storage.
我们可以使用命令 Get-PSDrive 查看当前的PSDrive。

5.2 Understanding how the filesystem is organized

Windows的文件系统主要以三种形式的对象组织:drives,folders和files。
其中drives是最顶级的对象,包含folders和files。
folders也是一种容器,包含files和其他folders。

PowerShell的术语和文件系统有点不同,因为一个PSDrive可能不指向文件系统,比如一个PSDrive可以映射成Windows注册表。
PowerShell也不使用术语file和folder,而是使用术语item

5.4 Navigating the filesystem

cmdlet Set-Location 可以改变shell的当前路径:

PS C:\> Set-Location -Path C:\Windows
PS C:\Windows>

使用 New-Item 创建文件夹要指定Type为directory,因为该命令还可以创建files、registry keys等东西:

PS C:\users\donjones\Documents> new-item testFolder
Type: directory
    Directory: C:\users\donjones\Documents
Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         3/29/2016  10:43 AM            testFolder

我们可以使用 mkdir 命令直接创建文件夹,而不输入type

5.5 Using wildcards and literal paths

Most of the item cmdlets include a -Path property, and by default that property accepts wildcards.
如果我们想表达 *,? 等符号原来的意思,我们可以使用参数 -LiteralPath ,该参数不支持通配符。

猜你喜欢

转载自blog.csdn.net/sinat_41104353/article/details/82181274