2015-09-24 78 views
1

我有一個使用PowerShell 3.0在Server 2008R2上運行得很好的腳本。 但是,在Server 2012R2和PowerShell 4.0上運行相同的腳本時,變量會變回空白。使用PowerShell 4.0從註冊表中獲取信息

我想從註冊表中讀取2個值。

Registry Key

下面是腳本:

#GET CRM INSTALL NAME FROM REGISTRY 
$GetInstallname = (Get-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\eWare\Mappings\|foreach {$_.PSBase.properties}| 
Select NAME | 
where {$_.Name -notlike ("PSPath")} | 
WHERE {$_.Name -notlike ("PSParentPath")}| 
where {$_.Name -notlike ("PSChildName")} | 
where {$_.Name -notlike ("PSDrive")} | 
where {$_.Name -notlike ("PSProvider")}) 
$CRMName = $GetInstallname -replace "/","" -replace "@{Name=","" -replace "}","" 

#GET CRM INSTALL DIR FROM REGISTRY 
$GetInstallDIR = (Get-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\eWare\Mappings\|foreach {$_.PSBase.properties}| 
Select VALUE | 
where {$_.Value -notlike ("Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\eWare\Mappings\")} | 
WHERE {$_.Value -notlike ("Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\eWare")}| 
where {$_.Value -notlike ("Mappings")} | 
where {$_.Value -notlike ("HKLM")} | 
where {$_.Value -notlike ("Microsoft.PowerShell.Core\Registry")}) 
$CRMPath = $GetInstallDIR -replace "@{Value=","" -replace "}","" -replace "WWWRoot","" 


$CRMNAME 
$CRMPath 

任何幫助將非常感激。

回答

2

雖然它不能解決現有的腳本,我建議只使用Get-Item和註冊表提供這樣:

$CRM = Get-Item -Path HKLM:\SOFTWARE\Wow6432Node\eWare\Mappings\ 
$GetInstallName = $CRM.Property 
$GetInstallDIR = $CRM.GetValue($GetInstallName) 
+0

謝謝TheMadTechnician!這解決了我的問題! – Creamore