【发布时间】:2017-02-20 15:23:13
【问题描述】:
谁能告诉我通过 Powershell ISE 运行 DSC 脚本与标准控制台(均以管理员身份运行)有什么区别?
当我通过 PS ISE 运行我的脚本时,一切正常,DSC 适用于 2 个服务器,包括。加密。但是,当我通过“使用 Powershell 运行”运行完全相同的脚本时,我收到了这样的错误消息:
System.Management.Automation.RuntimeException:您不能在空值表达式上调用方法。在 System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext,异常异常)在 System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame 帧)在 System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame 帧)在 System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame 框架)。
ScriptBlock 的第 1021 行,无文件:第 1 行
这些错误指向下面一行(粗体):
Configuration Config1
{
...
...
...
}
$configdata = @{
AllNodes = @(
@{
NodeName = "Server1"
PSDscAllowDomainUser = $true
CertificateFile = "$((Get-ChildItem 'E:\' | ? {$_.Name -like 'MyFolderName'}).fullname)\Server1.cer"
Thumbprint = ($Thumbs | ? {$_ -like "Server1*"}).Split("=")[1]
}
@{
NodeName = "Server2"
PSDscAllowDomainUser = $true
CertificateFile = "$((Get-ChildItem 'E:\' | ? {$_.Name -like MyFolderName'}).fullname)\Server2.cer"
Thumbprint = ($Thumbs | ? {$_ -like "Server2*"}).Split("=")[1]
}
)
}
Config1 -ConfigurationData $configdata
问题出在 Server2 上(我在 Server1 上运行脚本)。所有路径都正确,我可以在哈希表中使用这样的语法吗?
问题在于标准的 powershell 控制台,有人知道为什么 PS ISE 不返回任何错误吗?
【问题讨论】:
-
如果您看到在标准 powershell 控制台和 powershell ISE 中运行的代码之间存在差异,我会检查您的 powershell 配置文件。与标准控制台相比,将在 ISE 中运行不同的配置文件 powershell。 About Profiles
标签: powershell dsc