为什么 Powershell DSC MOF 生成对我不起作用?
Why does Powershell DSC MOF generation does not work for me?
我正在尝试编写我的第一个 Powershell DSC 脚本,它看起来很简单,除非它当然不起作用。
我的脚本名为 ScriptFolderConfig。ps1
这是我的脚本:
configuration ScriptFolder
{
param ($Node)
node $Node
{
File ScriptFiles
{
SourcePath = "\BRPSTFSBUILD01\Drops\share"
DestinationPath = "C:\scripts"
Ensure = "Present"
Type = "Directory"
Recurse = $true
}
}
}
从包含脚本的文件夹我 运行 .\ScriptFolderConfig.ps1 没有错误。
然后我尝试 运行 ScriptFolder,我收到错误:
ScriptFolder : The term 'ScriptFolder' is not recognized as the name
of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path
is correct and try again. At line:1 char:1
+ ScriptFolder
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (ScriptFolder:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
试试这个:
来自包含您的脚本的文件夹运行
. .\ScriptFolderConfig.ps1 # "." will load your function
然后重试。
我正在尝试编写我的第一个 Powershell DSC 脚本,它看起来很简单,除非它当然不起作用。
我的脚本名为 ScriptFolderConfig。ps1 这是我的脚本:
configuration ScriptFolder
{
param ($Node)
node $Node
{
File ScriptFiles
{
SourcePath = "\BRPSTFSBUILD01\Drops\share"
DestinationPath = "C:\scripts"
Ensure = "Present"
Type = "Directory"
Recurse = $true
}
}
}
从包含脚本的文件夹我 运行 .\ScriptFolderConfig.ps1 没有错误。 然后我尝试 运行 ScriptFolder,我收到错误:
ScriptFolder : The term 'ScriptFolder' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + ScriptFolder + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (ScriptFolder:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
试试这个:
来自包含您的脚本的文件夹运行
. .\ScriptFolderConfig.ps1 # "." will load your function
然后重试。