我是Powershell和动态状态配置的新手。我正在尝试使用部署脚本,它将在Windows任务计划程序中设置许多任务。我编写了脚本,并一直试图在我的本地机器上运行它。
Configuration AppServerTasks {
param($NodeName)
Import-DscResource -Module StackExchangeResources
Node $NodeName
{
$trackingFilePath = "...";
$tracksFilePath = "...";
$reportingFilePath = "...";
ScheduledTask TrackTask
{
Name = "Tracks"
FilePath = $tracksFilePath
Daily = $true
Hours = 0
Minutes = 5
}
ScheduledTask TrackingTask
{
Name = "Tracking"
FilePath = $trackingFilePath
Daily = $true
Hours = 0
Minutes = 5
}
ScheduledTask ReportingTask
{
Name = "Reporting"
FilePath = $reportingFilePath
Daily = $true
Hours = 0
Minutes = 5
}
}
}
AppServerTasks -NodeName "localhost"
Start-DscConfiguration AppServerTasks -Wait -Verbose -Force
但是,“访问被拒绝”失败了。我从中得到的错误如下:
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' =
MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer MEEP with user sid S-1-5-21-2331283068-2376342717-1560730737-1001.
VERBOSE: [MEEP]: LCM: [ Start Set ]
VERBOSE: [MEEP]: LCM: [ Start Resource ] [[ScheduledTask]TrackTask]
VERBOSE: [MEEP]: LCM: [ Start Test ] [[ScheduledTask]TrackTask]
VERBOSE: [MEEP]: [[ScheduledTask]TrackTask] Unable to find matching job.
VERBOSE: [MEEP]: LCM: [ End Test ] [[ScheduledTask]TrackTask] in 0.0160 seconds.
VERBOSE: [MEEP]: LCM: [ Start Set ] [[ScheduledTask]TrackTask]
Connecting to remote server MEEP failed with the following error message : Access is denied. For more information, see the
about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:) [], CimException
+ FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed
+ PSComputerName : localhost
Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.
+ CategoryInfo : InvalidData: (:) [], CimException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
+ PSComputerName : localhost
Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.
+ CategoryInfo : InvalidData: (:) [], CimException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
+ PSComputerName : localhost
VERBOSE: [MEEP]: LCM: [ End Set ] [[ScheduledTask]TrackTask] in 0.0150 seconds.
The PowerShell DSC resource StackExchange_ScheduledTask threw one or more non-terminating errors while running the
Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational.
Refer to this channel for more details.
+ CategoryInfo : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : NonTerminatingErrorFromProvider
+ PSComputerName : localhost
VERBOSE: [MEEP]: LCM: [ Start Resource ] [[ScheduledTask]TrackingTask]
VERBOSE: [MEEP]: LCM: [ Start Test ] [[ScheduledTask]TrackingTask]
VERBOSE: [MEEP]: [[ScheduledTask]TrackingTask] Unable to find matching job.
VERBOSE: [MEEP]: LCM: [ End Test ] [[ScheduledTask]TrackingTask] in 0.0000 seconds.
VERBOSE: [MEEP]: LCM: [ Start Set ] [[ScheduledTask]TrackingTask]
Connecting to remote server MEEP failed with the following error message : Access is denied. For more information, see the
about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:) [], CimException
+ FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed
+ PSComputerName : localhost
Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.
+ CategoryInfo : InvalidData: (:) [], CimException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
+ PSComputerName : localhost
Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.
+ CategoryInfo : InvalidData: (:) [], CimException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
+ PSComputerName : localhost
VERBOSE: [MEEP]: LCM: [ End Set ] [[ScheduledTask]TrackingTask] in 0.0320 seconds.
The PowerShell DSC resource StackExchange_ScheduledTask threw one or more non-terminating errors while running the
Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational.
Refer to this channel for more details.
+ CategoryInfo : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : NonTerminatingErrorFromProvider
+ PSComputerName : localhost
VERBOSE: [MEEP]: LCM: [ Start Resource ] [[ScheduledTask]ReportingTask]
VERBOSE: [MEEP]: LCM: [ Start Test ] [[ScheduledTask]ReportingTask]
VERBOSE: [MEEP]: [[ScheduledTask]ReportingTask] Unable to find matching job.
VERBOSE: [MEEP]: LCM: [ End Test ] [[ScheduledTask]ReportingTask] in 0.0000 seconds.
VERBOSE: [MEEP]: LCM: [ Start Set ] [[ScheduledTask]ReportingTask]
Connecting to remote server MEEP failed with the following error message : Access is denied. For more information, see the
about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:) [], CimException
+ FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed
+ PSComputerName : localhost
Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.
+ CategoryInfo : InvalidData: (:) [], CimException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
+ PSComputerName : localhost
Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.
+ CategoryInfo : InvalidData: (:) [], CimException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
+ PSComputerName : localhost
VERBOSE: [MEEP]: LCM: [ End Set ] [[ScheduledTask]ReportingTask] in 0.0150 seconds.
The PowerShell DSC resource StackExchange_ScheduledTask threw one or more non-terminating errors while running the
Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational.
Refer to this channel for more details.
+ CategoryInfo : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : NonTerminatingErrorFromProvider
+ PSComputerName : localhost
The SendConfigurationApply function did not succeed.
+ CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 1
+ PSComputerName : localhost
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.139 seconds
我尝试过谷歌搜索(因为我不知道问题的背景原因)。但它并没有帮助,尽管其他人也遇到过类似的问题,但修正建议并没有奏效。我在POwershell ISE中以管理员身份运行此操作。我试过了Enable-PSRemoting -force
并启用了它。不知道下一步该怎么做。
你的想法?感谢。
答案 0 :(得分:0)
似乎必须提供凭证:
$ConfigurationData = @{
AllNodes = @(
@{
NodeName="*"
PSDscAllowPlainTextPassword=$true
}
@{
NodeName="Localhost"
}
)
}
Configuration AppServerTasks {
param($NodeName,$credential)
Import-DscResource -ModuleName StackExchangeResources
Node $AllNodes.NodeName
{
$trackingFilePath = 'c:\temp\test.ps1'
ScheduledTask TrackTask
{
Name = "Tracks"
FilePath = $trackingFilePath
Daily = $true
Hours = 0
Minutes = 5
Credential = $credential
}
}
}
$c = Get-Credential
AppServerTasks -ConfigurationData $ConfigurationData -OutputPath c:\temp\localhost -credential $c
Start-DscConfiguration -ComputerName localhost -Path C:\temp\localhost -Wait -Verbose -Force