我有Windows 10 / Windows 2016 TP5(PowerShell 5.1)。我想在配置中使用来自GitHub的PowerShell DSC模块,例如xTimeZone。
我应该怎么做才能引用它Import-DSCResource
?
这是我第一次尝试添加模块(不是基于安装程序的产品中的模块),也许我缺少明显的东西。是否没有git clone
基于pip
或类似的过程gem
?
我验证了的值,$env:PSModulePath
并定义了两个目录:C:\Users\techraf\Documents\WindowsPowerShell\Modules;C:\Windows\system32\W indowsPowerShell\v1.0\Modules
。
我将xTimeZone目录的内容复制到C:\Users\techraf\Documents\WindowsPowerShell\Modules
。
PowerShell无法看到它。试图在存储库的不同级别上进行复制-均失败。
运行示例脚本时,我得到:
At line:12 char:4
+ Import-DSCResource -ModuleName xTimeZone
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Could not find the module 'xTimeZone'.
At line:16 char:9
+ xTimeZone TimeZoneExample
+ ~~~~~~~~~
Undefined DSC resource 'xTimeZone'. Use Import-DSCResource to import the resource.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : ModuleNotFoundDuringParse
根据答案的建议,将模块从C:\Users\techraf\Documents\WindowsPowerShell\Modules
移到C:\Windows\system32\W indowsPowerShell\v1.0\Modules
第一个错误后,消失了,我只得到了:
At line:16 char:9
+ xTimeZone TimeZoneExample
+ ~~~~~~~~~
Undefined DSC resource 'xTimeZone'. Use Import-DSCResource to import the resource.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ResourceNotDefined
关于DSC资源
本质上,DSC资源是专用的PowerShell模块。资源模块必须导出Get,Set和Test-TargetResource命令(PowerShell 5中提供了另一个选项,但在xTimeZone上下文中超出范围)。
资源始终按以下结构进行部署:
<Modules>\<ModuleName>\DSCResources\<ResourceName>
Get-DscResource在DSCResources文件夹中查找“模块”,作为现有模块的子文件夹。如果看不到资源,则无法使用。
xTimeZone
xTimeZone包含:
除非正确部署,否则Windows PowerShell无法找到该资源。这些说明适用于下载模块。
xTimeZone-master
为xTimeZone
。xTimeZone
到C:\Program Files\WindowsPowerShell\Modules
验证您可以发现DSCResource:
Get-DscResource
如果由于某种原因,您在使用Program Files \ Modules时遇到问题,则可以使用:
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\
但是,由于该区域是操作系统文件的一部分,因此优先级较低。
配置
找到资源后,需要将其导入到要使用它的每个Configuration元素中。
Configuration SomeConfiguration {
Import-DscResource -ModuleName xTimeZone
# Nodes statement follows
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句