Powershell DSC无法安装模块

时间:2018-07-10 23:22:56

标签: powershell dsc

我已经阅读并尝试了数小时才能找到的所有内容,但都没有成功...

我已经设置了Powershell DSC Pull服务器。它正在使用现成的DSC资源。

也就是说,以下代码可以正常工作,并且可以毫无错误地推送到客户端计算机:

$ConfigurationData = @{
    AllNodes = @(
        @{
            NodeName="*"
            PSDscAllowPlainTextPassword = $true
            PSDscAllowDomainUser = $true
        },
        @{
            NodeName = $ComputerName
        }
    )
}

Configuration SetPullMode {
    param (
        [string]$ComputerName
    )
    Node $ComputerName {
        LocalConfigurationManager {
            AllowModuleOverwrite = $true
            ConfigurationMode = 'ApplyAndAutoCorrect'
            RefreshMode = 'Pull'
            RefreshFrequencyMins = 30
            ConfigurationModeFrequencyMins = 60
            RebootNodeIfNeeded = $true
            DownloadManagerName = 'WebDownloadManager'
            DownloadManagerCustomData = ${
                ServerUrl = 'http://holo-rdm-dsc:8080/PSDSCPullServer.svc';
                AllowUnsecureConnection = 'true'
            }
        }
    }
}

Configuration TestDSCState {
    param (
        [string[]]$ComputerName
    )

    Import-DscResource –ModuleName 'PSDesiredStateConfiguration'

    Node $ComputerName {

        File CreateLogsDirectory {
            DestinationPath = 'C:\logs'
            Ensure = "Present"
            Force = $true
            Type = 'Directory'
        }

        File CreateTestFile {
            DestinationPath = "C:\logs\TestFile.txt"
            Ensure = "Present"
            Force = $true
            Type = 'File'
            Contents = "This `r`n is `r`n TestFileOne"
        }
    }
}

$ComputerName = 'holo-dsc-tst3'

SetPullMode -ComputerName $ComputerName -OutputPath 'C:\Users\v-jodev\Desktop\TestDSCState' -ConfigurationData $ConfigurationData
Set-DscLocalConfigurationManager -ComputerName $ComputerName -Path C:\Users\v-jodev\Desktop\TestDSCState -Verbose

TestDSCState -ComputerName $ComputerName -ConfigurationData $ConfigurationData -OutputPath 'C:\Users\v-jodev\Desktop\TestDSCState'

$Source="C:\Users\v-jodev\Desktop\TestDSCState\$ComputerName.mof"
#$Destination="C:\Program Files\WindowsPowerShell\DscService\Configuration\$GUID.mof"
$Destination="C:\Program Files\WindowsPowerShell\DscService\Configuration\$ComputerName.mof"
Copy $Source $Destination -Verbose -Force
New-DSCChecksum $Destination -Verbose -Force

Start-DscConfiguration -ComputerName $ComputerName -Path "C:\Program Files\WindowsPowerShell\DscService\Configuration" -Wait -Force -Verbose

以上代码的输出:

    Directory: C:\Users\v-jodev\Desktop\TestDSCState


Mode                LastWriteTime         Length Name                                                                                                                                                                                                                                                                                     
----                -------------         ------ ----                                                                                                                                                                                                                                                                                     
-a----        7/10/2018   4:06 PM           1510 holo-dsc-tst3.meta.mof                                                                                                                                                                                                                                                                   
VERBOSE: Performing the operation "Start-DscConfiguration: SendMetaConfigurationApply" on target "MSFT_DSCLocalConfigurationManager".
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendMetaConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer HOLO-RDM-DSC with user sid S-1-5-21-2127521184-1604012920-1887927527-22118087.
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ Start  Set      ]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ Start  Resource ]  [MSFT_DSCMetaConfiguration]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ Start  Set      ]  [MSFT_DSCMetaConfiguration]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ End    Set      ]  [MSFT_DSCMetaConfiguration]  in 0.0460 seconds.
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ End    Resource ]  [MSFT_DSCMetaConfiguration]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ End    Set      ]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ End    Set      ]    in  0.1090 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Set-DscLocalConfigurationManager finished in 0.349 seconds.
-a----        7/10/2018   4:06 PM           2850 holo-dsc-tst3.mof                                                                                                                                                                                                                                                                        
VERBOSE: Performing the operation "Copy File" on target "Item: C:\Users\v-jodev\Desktop\TestDSCState\holo-dsc-tst3.mof Destination: C:\Program Files\WindowsPowerShell\DscService\Configuration\holo-dsc-tst3.mof".
VERBOSE: Overwrite checksum file 'C:\Program Files\WindowsPowerShell\DscService\Configuration\holo-dsc-tst3.mof.checksum'
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 HOLO-RDM-DSC with user sid S-1-5-21-2127521184-1604012920-1887927527-22118087.
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ Start  Set      ]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ Start  Resource ]  [[File]CreateLogsDirectory]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ Start  Test     ]  [[File]CreateLogsDirectory]
VERBOSE: [HOLO-DSC-TST3]:                            [[File]CreateLogsDirectory] The destination object was found and no action is required.
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ End    Test     ]  [[File]CreateLogsDirectory]  in 0.0310 seconds.
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ Skip   Set      ]  [[File]CreateLogsDirectory]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ End    Resource ]  [[File]CreateLogsDirectory]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ Start  Resource ]  [[File]CreateTestFile]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ Start  Test     ]  [[File]CreateTestFile]
VERBOSE: [HOLO-DSC-TST3]:                            [[File]CreateTestFile] The destination object was found and no action is required.
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ End    Test     ]  [[File]CreateTestFile]  in 0.0160 seconds.
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ Skip   Set      ]  [[File]CreateTestFile]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ End    Resource ]  [[File]CreateTestFile]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ End    Set      ]
VERBOSE: [HOLO-DSC-TST3]: LCM:  [ End    Set      ]    in  0.5000 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.707 seconds

以及在客户端计算机上创建的结果文件:

PS C:\> ls .\logs\


    Directory: C:\logs


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        7/10/2018   4:00 PM             28 TestFile.txt


PS C:\> cat .\logs\TestFile.txt
This
 is
 TestFileOne

我遇到的问题是从Powershell Gallery添加模块失败。

我添加适当的Import-DscResource块:

Import-DscResource -ModuleName ”xRemoteDesktopAdmin” -ModuleVersion "1.1.0.0"

代码块本身:

    xRemoteDesktopAdmin EnableRemoteDesktop {
        Ensure = "Present"
        UserAuthentication = "Secure"
    }

除了这次,发生错误:

A generic exception occurred during the invocation of the Get-DSCModule cmdlet by Download Manager WebDownloadManager. Could not install module dependencies needed by the configuration.
    + CategoryInfo          : InvalidType: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : GetModuleExecutionFailure
    + PSComputerName        : holo-dsc-tst3

客户端计算机本身上的错误:

Job {E7BF096A-8496-11E8-B491-00155DBC9F10} : 
MIResult: 1
Error Message: A generic exception occurred during the invocation of the Get-DSCModule cmdlet by Download Manager WebDownloadManager. Could not install module dependencies needed by the configuration.
Message ID: GetModuleExecutionFailure
Error Category: 9
Error Code: 1
Error Type: MI

我已经检查了该模块存在的一百次:

PS C:\Windows\system32> Install-Module xRemoteDesktopAdmin
PS C:\Windows\system32> Import-Module xRemoteDesktopAdmin
PS C:\Windows\system32> Get-Module xRemoteDesktopAdmin

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   1.1.0.0    xRemoteDesktopAdmin


PS C:\Windows\system32> Get-Module xRemoteDesktopAdmin | Publish-ModuleToPullServer
VERBOSE: Preparing to compress...
VERBOSE: Performing the operation "Compress-Archive" on target "
C:\Program Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\DSCResources
C:\Program Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\Examples
C:\Program Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\appveyor.yml
C:\Program Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\LICENSE
C:\Program Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\README.md
C:\Program Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\xRemoteDesktopAdmin.psd1".
VERBOSE: Adding 'C:\Program
Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\DSCResources\xRemoteDesktopAdmin\xRemoteDesktopAdmin.psm1'.
VERBOSE: Adding 'C:\Program
Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\DSCResources\xRemoteDesktopAdmin\xRemoteDesktopAdmin.schema
.mof'.
VERBOSE: Adding 'C:\Program
Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\Examples\ExampleConfiguration-RemoteDesktopAdmin.ps1'.
VERBOSE: Adding 'C:\Program
Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\Examples\ExampleConfiguration-RemoteDesktopAdminWithEncrypt
edPassword.ps1'.
VERBOSE: Adding 'C:\Program
Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\Examples\ExampleConfiguration-RemoteDesktopAdminWithUnEncry
ptedPassword.ps1'.
VERBOSE: Adding 'C:\Program Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\appveyor.yml'.
VERBOSE: Adding 'C:\Program Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\LICENSE'.
VERBOSE: Adding 'C:\Program Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\README.md'.
VERBOSE: Adding 'C:\Program Files\WindowsPowerShell\Modules\xRemoteDesktopAdmin\1.1.0.0\xRemoteDesktopAdmin.psd1'.

并且其正确命名和版本化的.zip文件和校验和存在:

PS C:\Windows\system32> Get-ChildItem 'C:\Program Files\WindowsPowerShell\DscService\Modules'


    Directory: C:\Program Files\WindowsPowerShell\DscService\Modules


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        7/10/2018   4:04 PM           8232 xRemoteDesktopAdmin_1.1.0.0.zip
-a----        7/10/2018   4:04 PM             64 xRemoteDesktopAdmin_1.1.0.0.zip.checksum

其内容正确无误:

enter image description here

在这一点上,我感到很沮丧。我尝试,阅读或发现的所有内容均无任何效果。请帮忙!

0 个答案:

没有答案