PowerShell DSC 현재 구성에 대한 실행 컨텍스트는 무엇입니까?
-
21-12-2019 - |
문제
DSC를 통해 PowerShell 프로파일을 배포하려고합니다. 구성은 .ps1 파일을 네트워크 공유에서 로컬 경로로 복사해야합니다.
스크립트를 실행하면 sourcepath는 현재 구성에 액세스 할 수 있어야합니다. 이 경로는 콘솔에서 액세스 할 수 있으므로 DSC 구성 중에 사용자 / 컨텍스트가 사용됩니까?
여기에 스크립트가 있습니다
@ ravikanth의 답장 이후 편집
$ConfigurationData = @{
AllNodes = @(
@{
NodeName="*"
PSDscAllowPlainTextPassword=$true
}
)
}
Configuration MyProfile
{
param ([string[]]$MachineName,
[PSCredential]$Credential)
Node $MachineName
{
Log startconfig
{
# The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
Message = "starting the file resource with ID MyProfile with $($myinvocation.mycommand) user : $env:username"
}
File profile
{
Credential=$credential
Ensure = 'Present'
SourcePath = "\\web-mridf\powershell\profil_1.ps1"
DestinationPath = "c:\temp\test.txt"
Type = "File" # Default is "File".
DependsOn = "[Log]startconfig"
}
Log AfterDirectoryCopy
{
# The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
Message = "Finished running the file resource with ID MyProfile"
DependsOn = "[File]profile" # This means run "MyProfile" first.
}
}
}
MyProfile -MachineName web-mridf -OutputPath c:\temp\dsc
Start-DscConfiguration -Path c:\temp\dsc -credential (get-credential("DOMAIN\user")) -force -verbose -Wait
.
및 오류 수신 ( 잘못된 인수 )
PS C:\temp> .\dsc.ps1
Répertoire : C:\temp\dsc
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 04/06/2014 10:54 2834 web-mridf.mof
COMMENTAIRES : Effectuez l'opération « Invoquer une méthode CIM » avec les
paramètres suivants : « 'methodName' = SendConfigurationApply,'className' =
MSFT_DSCLocalConfigurationManager,'namespaceName' =
root/Microsoft/Windows/DesiredStateConfiguration ».
COMMENTAIRES : [WEB-MRIDF] : [[File]profile]
SourcePath must be accessible for current configuration.
COMMENTAIRES : [WEB-MRIDF] : [[File]profile] The
related file/directory is: \\web-mridf\powershell\profil_1.ps1.
SourcePath must be accessible for current configuration. The related
file/directory is: \\web-mridf\powershell\profil_smac.ps1. . L'ID de ressource
associé est [File]profile.
+ CategoryInfo : InvalidArgument : (:) [], CimException
+ FullyQualifiedErrorId : MI RESULT 4
+ PSComputerName : web-mridf
COMMENTAIRES : [WEB-MRIDF] : Gestionnaire de configuration local : [ Fin
Définir ]
La fonction SendConfigurationApply n'a pas réussi.
+ CategoryInfo : InvalidArgument : (root/Microsoft/...gurationMan
ager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 4
+ PSComputerName : web-mridf
COMMENTAIRES : L'opération « Invoquer une méthode CIM » est terminée.
COMMENTAIRES : Le temps nécessaire à l'exécution du travail de configuration
est de 0.881 secondes
. 해결책
DSC 로컬 구성 관리자가 시스템으로 실행됩니다. 그래서 그 공유에 액세스 할 수는 없습니다. 자격 증명을 전달하여 공유에 액세스해야합니다. 자격 증명의 경우 인증서를 사용하여 암호를 암호화하거나 일반 텍스트 암호를 사용해야합니다.
일반 텍스트 암호의 경우 PowerShell 매거진에 게시 한 기사를 확인하십시오. http : // www. PowerShellMagazine.com/2013/09/26/using-the-credential-attribute-of-dsc-file-resource/
암호 암호화에 대한 인증서를 사용하려면 PS 팀 블로그 게시물을 http://blogs.msdn.com/b/powershell/archive/2014/01/31/want- 보안 자격 증명 - 인-Windows-PowerShell-resouple-configuration.aspx
아래의 주석을 기반으로 업데이트 :
$ allnodes.nodename은 구성 데이터를 사용할 때의 키입니다. 그것을 정적 노드 이름으로 대체하지 마십시오.
$ConfigurationData = @{
AllNodes = @(
@{
NodeName="*"
PSDscAllowPlainTextPassword=$true
}
@{
NodeName="ServerName"
}
)
}
Configuration MyProfile
{
param (
[PSCredential]$Credential
)
Node $AllNodes.NodeName
{
Log startconfig
{
# The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
Message = "starting the file resource with ID MyProfile with $($myinvocation.mycommand) user : $env:username"
}
File profile
{
Credential=$credential
Ensure = 'Present'
SourcePath = "e:\powershell\profil_smac.ps1"
DestinationPath = "c:\temp\test2.txt2"
Type = "File" # Default is "File".
DependsOn = "[Log]startconfig"
}
Log AfterDirectoryCopy
{
# The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
Message = "Finished running the file resource with ID MyProfile"
DependsOn = "[File]profile" # This means run "MyProfile" first.
}
}
}
MyProfile -configurationdata $configurationdata -machinename "web-mridf.groupe.sa.colas.com" -credential (get-credential("groupe\sys-mac-smacsr")) -OutputPath c:\temp\dsc
Start-DscConfiguration -Path c:\temp\dsc -force -verbose -Wait
.