为什么这种使用共享文件夹的 DSC 文件资源只成功一次?
Why does this use of DSC File Resource using shared folder only succeed once?
我正在测试使用 DSC 文件资源将文件目录从共享文件夹复制到另一台计算机。
我的问题是,这可以工作一次,但 运行第二次使用相同的代码会失败。如果我重新启动目标机器,脚本将再次 运行 正确但第二次失败。
谁能告诉我这是为什么,我是否需要做一些不同的事情?
我使用的机器叫:
"S1" => Server 2012 R2(具有读取权限的共享文件夹和用户设置)
"S2" => Virtual Server 2012 R2 运行ning on S1(这是目标机器)
我运行ning的脚本是这样的:
$ConfigurationData = @{
AllNodes = @(
@{
NodeName="*"
PSDscAllowPlainTextPassword = $true
}
@{
NodeName = "S2"
}
)
}
Configuration Test {
param (
[Parameter(Mandatory=$true)]
[PSCredential]$credential
)
Node $AllNodes.NodeName {
File DirectoryCopy {
DestinationPath = "C:\Shared\Files"
SourcePath = "\S1\Shared\Files"
Ensure = "present"
Credential = $credential
Type = "Directory"
Recurse = $true
}
}
}
$username = "dscUser"
$password="dscPassword!"|ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PsCredential("$username",$password)
Test -OutputPath "C:\Scripts" -ConfigurationData $ConfigurationData -Credential $credential
Start-DscConfiguration -ComputerName S2 -path "C:\Scripts" -Verbose -Wait
这两次运行的输出是这样的:
PS C:\repo> C:\Scripts\Test.ps1
Directory: C:\Scripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 16/10/2015 11:12 1646 S2.mof
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = ro
ot/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer S1 with user sid S-1-5-21-1747786857-595474378-2516325245-500.
VERBOSE: [S2]: LCM: [ Start Set ]
VERBOSE: [S2]: LCM: [ Start Resource ] [[File]DirectoryCopy]
VERBOSE: [S2]: LCM: [ Start Test ] [[File]DirectoryCopy]
VERBOSE: [S2]: [[File]DirectoryCopy] Building file list from cache.
VERBOSE: [S2]: LCM: [ End Test ] [[File]DirectoryCopy] in 0.2500 seconds.
VERBOSE: [S2]: LCM: [ Start Set ] [[File]DirectoryCopy]
VERBOSE: [S2]: [[File]DirectoryCopy] Building file list from cache.
VERBOSE: [S2]: LCM: [ End Set ] [[File]DirectoryCopy] in 0.2660 seconds.
VERBOSE: [S2]: LCM: [ End Resource ] [[File]DirectoryCopy]
VERBOSE: [S2]: LCM: [ End Set ]
VERBOSE: [S2]: LCM: [ End Set ] in 0.6720 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 1.59 seconds
PS C:\repo> C:\Scripts\Test.ps1
Directory: C:\Scripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 16/10/2015 11:13 1646 S2.mof
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = ro
ot/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer S1 with user sid S-1-5-21-1747786857-595474378-2516325245-500.
VERBOSE: [S2]: LCM: [ Start Set ]
VERBOSE: [S2]: LCM: [ Start Resource ] [[File]DirectoryCopy]
VERBOSE: [S2]: LCM: [ Start Test ] [[File]DirectoryCopy]
VERBOSE: [S2]: [[File]DirectoryCopy] An error occurs when accessing the network share with the specified credential. Please make sure the credential is c
orrect and the network share is accessible. Note that Credential should not be specified with the local path.
VERBOSE: [S2]: [[File]DirectoryCopy] The related file/directory is: \S1\Shared\Files.
A specified logon session does not exist. It may already have been terminated. An error occurs when accessing the network share with the specified credential. Please make sure
the credential is correct and the network share is accessible. Note that Credential should not be specified with the local path. The related file/directory is: \S1\Shared\Files.
+ CategoryInfo : NotSpecified: (:) [], CimException
+ FullyQualifiedErrorId : Windows System Error 1312
+ PSComputerName : S2
VERBOSE: [S2]: LCM: [ End Set ]
LCM failed to move one or more resources to their desired state.
+ CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 1
+ PSComputerName : S2
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 3.027 seconds
感谢任何帮助,因为它让我抓狂。
谢谢。
我(认为)我找到了答案。
指定用户名时我应该使用 'S1\dscUser' 而不是 'dscUser'.
这些机器不在域中。
我正在测试使用 DSC 文件资源将文件目录从共享文件夹复制到另一台计算机。
我的问题是,这可以工作一次,但 运行第二次使用相同的代码会失败。如果我重新启动目标机器,脚本将再次 运行 正确但第二次失败。
谁能告诉我这是为什么,我是否需要做一些不同的事情?
我使用的机器叫:
"S1" => Server 2012 R2(具有读取权限的共享文件夹和用户设置)
"S2" => Virtual Server 2012 R2 运行ning on S1(这是目标机器)
我运行ning的脚本是这样的:
$ConfigurationData = @{
AllNodes = @(
@{
NodeName="*"
PSDscAllowPlainTextPassword = $true
}
@{
NodeName = "S2"
}
)
}
Configuration Test {
param (
[Parameter(Mandatory=$true)]
[PSCredential]$credential
)
Node $AllNodes.NodeName {
File DirectoryCopy {
DestinationPath = "C:\Shared\Files"
SourcePath = "\S1\Shared\Files"
Ensure = "present"
Credential = $credential
Type = "Directory"
Recurse = $true
}
}
}
$username = "dscUser"
$password="dscPassword!"|ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PsCredential("$username",$password)
Test -OutputPath "C:\Scripts" -ConfigurationData $ConfigurationData -Credential $credential
Start-DscConfiguration -ComputerName S2 -path "C:\Scripts" -Verbose -Wait
这两次运行的输出是这样的:
PS C:\repo> C:\Scripts\Test.ps1
Directory: C:\Scripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 16/10/2015 11:12 1646 S2.mof
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = ro
ot/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer S1 with user sid S-1-5-21-1747786857-595474378-2516325245-500.
VERBOSE: [S2]: LCM: [ Start Set ]
VERBOSE: [S2]: LCM: [ Start Resource ] [[File]DirectoryCopy]
VERBOSE: [S2]: LCM: [ Start Test ] [[File]DirectoryCopy]
VERBOSE: [S2]: [[File]DirectoryCopy] Building file list from cache.
VERBOSE: [S2]: LCM: [ End Test ] [[File]DirectoryCopy] in 0.2500 seconds.
VERBOSE: [S2]: LCM: [ Start Set ] [[File]DirectoryCopy]
VERBOSE: [S2]: [[File]DirectoryCopy] Building file list from cache.
VERBOSE: [S2]: LCM: [ End Set ] [[File]DirectoryCopy] in 0.2660 seconds.
VERBOSE: [S2]: LCM: [ End Resource ] [[File]DirectoryCopy]
VERBOSE: [S2]: LCM: [ End Set ]
VERBOSE: [S2]: LCM: [ End Set ] in 0.6720 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 1.59 seconds
PS C:\repo> C:\Scripts\Test.ps1
Directory: C:\Scripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 16/10/2015 11:13 1646 S2.mof
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = ro
ot/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer S1 with user sid S-1-5-21-1747786857-595474378-2516325245-500.
VERBOSE: [S2]: LCM: [ Start Set ]
VERBOSE: [S2]: LCM: [ Start Resource ] [[File]DirectoryCopy]
VERBOSE: [S2]: LCM: [ Start Test ] [[File]DirectoryCopy]
VERBOSE: [S2]: [[File]DirectoryCopy] An error occurs when accessing the network share with the specified credential. Please make sure the credential is c
orrect and the network share is accessible. Note that Credential should not be specified with the local path.
VERBOSE: [S2]: [[File]DirectoryCopy] The related file/directory is: \S1\Shared\Files.
A specified logon session does not exist. It may already have been terminated. An error occurs when accessing the network share with the specified credential. Please make sure
the credential is correct and the network share is accessible. Note that Credential should not be specified with the local path. The related file/directory is: \S1\Shared\Files.
+ CategoryInfo : NotSpecified: (:) [], CimException
+ FullyQualifiedErrorId : Windows System Error 1312
+ PSComputerName : S2
VERBOSE: [S2]: LCM: [ End Set ]
LCM failed to move one or more resources to their desired state.
+ CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 1
+ PSComputerName : S2
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 3.027 seconds
感谢任何帮助,因为它让我抓狂。
谢谢。
我(认为)我找到了答案。
指定用户名时我应该使用 'S1\dscUser' 而不是 'dscUser'.
这些机器不在域中。