2016-08-24 68 views
3

這是我打的錯誤:「PowerShell提供<模塊>不會在PowerShell模塊路徑存在也不是註冊爲WMI提供程序」DSC - 模塊沒有在PowerShell模塊路徑存在

我並不是PowerShell和DSC的新手,但我很難搞清楚這一點。我遵循指導here進行故障排除。我也發現this almost identical question ......唯一的解決方案似乎是重新啓動(我試過)。

所以我做了一個導入模塊OctopusDSC的配置。我排除故障的模塊導入過程中留下了很多的參數,但這裏是我有:在C:\Program Files\WindowsPowerShell\Modules都存在

Configuration OctopusServer 
{ 
    Import-DscResource -Module OctopusDSC 

    Node "WIN-ABC123" 
    { 
     cTentacleAgent OctopusTentacle 
     { 
      Ensure = "Present" 
      State = "Started" 
      Name = "Tentacle" 
      ApiKey = "" 
      OctopusServerUrl = "" 
      DefaultApplicationDirectory = "C:\Utility" 
     } 
    } 
} 

模塊本地和服務器上:

C:\>tree "C:\Program Files\WindowsPowerShell\Modules" /f 
Folder PATH listing 
Volume serial number is 9EC4-62C1 
C:\PROGRAM FILES\WINDOWSPOWERSHELL\MODULES 
└───OctopusDSC 
    │ OctopusDSC.psd1 
    │ 
    └───DSCResources 
     └───cTentacleAgent 
       cTentacleAgent.psm1 
       cTentacleAgent.schema.mof 

模塊路徑似乎細(我把回車在每個分號,爲了可讀性):

PS C:\> $env:PSModulePath 
C:\Users\jasonc\Documents\WindowsPowerShell\Modules; 
C:\Program Files\WindowsPowerShell\Modules; 
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\; 
C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell 

我可以調用Get-Module

PS C:\> Get-Module OctopusDSC -ListAvailable 

    Directory: C:\Program Files\WindowsPowerShell\Modules 

ModuleType Version Name        ExportedCommands 
---------- ------- ----        ---------------- 
Manifest 1.0.1  OctopusDSC       {Get-TargetResource, Set-TargetResource, Test-TargetResource} 

我可以叫Get-DscResource

PS C:\temp> Get-DscResource -Name "cTentacleAgent" 

ImplementedAs Name      Module       Properties 
------------- ----      ------       ---------- 
PowerShell  cTentacleAgent   OctopusDSC      {Name, ApiKey, DefaultApplicationDirectory,... 

這是我的錯誤:

PS C:\> Start-DscConfiguration -Path .\OctopusServer -Verbose -WhatIf -Wait 
What if: [WIN-ABC123]: LCM: [ Start Set  ] 
What if: [WIN-ABC123]: LCM: [ End Set  ] 
The PowerShell provider OctopusDSC does not exist at the PowerShell module path nor is it registered as a WMI provider. 
    + CategoryInfo   : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException 
    + FullyQualifiedErrorId : ModuleNameNotFound 
    + PSComputerName  : WIN-ABC123 

我缺少的東西?

PS C:\> $PSVersionTable 

Name       Value 
----       ----- 
PSVersion      4.0 
WSManStackVersion    3.0 
SerializationVersion   1.1.0.1 
CLRVersion      4.0.30319.34014 
BuildVersion     6.3.9600.16394 
PSCompatibleVersions   {1.0, 2.0, 3.0, 4.0} 
PSRemotingProtocolVersion  2.2 

更新

我注意到了這個問題發生在機器上安裝了Microsoft監視代理,但如果不安裝該代理不會發生。

的安裝後,PSModulePath機級的環境變量看起來是這樣的(分開的清晰度)後:

PS C:\> [environment]::GetEnvironmentVariable("PSModulePath","Machine") 
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\; 
C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell 

如果我刪除代理的路徑,只留下有C:\Windows\system32\WindowsPowerShell\v1.0\Modules\,OctopusDSC發現。我必須重新啓動WMI Provider Host進程才能進行環境變量更改。如果我將路徑添加回失敗。

現在這讓我感到困惑,因爲模塊安裝的實際路徑的整個時間是C:\Program Files\WindowsPowerShell\Modules,並且這是由PowerShell本身添加到計算的PSModulePath(我假設因爲我通常沒有看到該路徑在系統環境變量中設置)。

我在其他地方看到在PSModulePath中複製C:\Program Files\WindowsPowerShell\Modules會導致模塊分辨率問題。那麼周圍可能還有其他的錯誤和敏感性?

我覺得這是一種答案,但我仍在尋找解決方法,因爲刪除該路徑不是首選。

+0

嘗試命令'Get-DscResource'來查看它是否可以發現cTentacleAgent。 'Get-Module'將只顯示它的容器,而不是資源。這個問題意味着資源在某種程度上是無效的,我可能會先檢查你的PowerShell版本(合理的期望和所有這些)。 –

+0

剛剛嘗試過......它找到了資源,但錯誤仍然存​​在:/。我用結果更新了我的問題。 –

+0

服務器上的PS版本?你能確定你的DSC資源不存在於程序文件以外的任何其他資源嗎? –

回答

0

作爲一個完整的檢查,看看你的。正在創建MOF ...那裏有其他MOF文件嗎? Start-DscConfiguration在一個目錄中運行所有的MOF。我改名爲我的MOF文件,不能讓錯誤消失,直到最終實現的錯誤是在舊財政部:(

0

你看到this post

除了一些補丁(2015年)也談到需要遞歸運行解鎖文件,我想我已經遇到過這種情況

1

這是WMF 4.0中的一個已知問題您是否使用WMF 4.0?切換到WMF 5.0會解決這個問題,除非你遇到安迪提到的Windows 10更新補丁問題。

+0

WMF 4由Server 2012 R2提供。是的,我想知道WMF 5是否有這個問題。 –