如何使用 PowerShell 安装 DSC 资源?
microsoft technologiespowershellsoftware & coding
要使用 PowerShell 安装 DSC 资源,我们可以使用与在 PowerShell 中安装模块相同的命令:(Install-Module)。
Find-DscResource 命令可以获取所有可用的 DSC 资源。要搜索特定的 DSC 资源,可以在 Find-DscResource 命令中提供 -Name 参数。例如,我们需要搜索 FilesAndFolder DSC 资源。
Find-DSCResource -Name filesandfolders
输出
Name Version ModuleName Repository ---- ------- ---------- ---------- FilesAndFolders 0.3.212 CommonTasks PSGallery
要安装此模块,我们可以使用管道执行 Install-Module 命令。
Find-DSCResource -Name filesandfolders | Install-Module -Force -Verbose
模块安装完成后,我们可以使用 Get-DSCResource 命令检查模块是否已正确安装。
Get-DscResource -Name FilesAndFolders
输出
![]()
要检查已安装模块的属性,我们可以使用以下命令。
Get-DscResource -Name FilesAndFolders | Select -ExpandProperty Properties
输出
Name PropertyType IsMandatory Values
---- ------------ ----------- ------
DependsOn [String[]] False {}
PsDscRunAsCredential [PSCredential] False {}
Items [Hashtable[]] True {}

