我正試圖根據作業系統的版本進行注冊密鑰變更。 鑰匙變更拍子作業得很好,但是我無法使用if功能來確定設備是否需要它。任何建議都是有幫助的。下面是powerhell。
$verCheckOS = (Get-WmiObject win32_operatingsystem) .version
if ($verCheckOS -lt 10.0. 19043 -and $verCheckOS -gt 10.0.17134)
{
if (Test-Path HKLM:SOFTWAREPoliciesMicrosoftAzureADAccount)
{
CD HKLM:SOFTWAREPoliciesMicrosoft
New-Item -Name AzureADAccount
New-ItemProperty -Path "AzureADAccount"/span> -Name "AllowPasswordReset"/span> -Value 1 -PropertyType DWord
}
}
Else
{
}
uj5u.com熱心網友回復:
為了使PowerShell正確地比較版本號,你需要把它們投到適當的型別。
$verCheckOS = [version](Get-CimInstance -ClassName CIM_OperatingSystem) .Version
if ($verCheckOS -lt [version]'10.0. 19043' -and $verCheckOS -gt [version]'10.0.17134') {
if (-not (Test-Path HKLM:SOFTWAREPoliciesMicrosoftAzureADAccount) ) {
推送位置 'HKLM:SOFTWAREPoliciesMicrosoft'
新建-專案 -名稱 'AzureADAccount'
New-ItemProperty -Path 'AzureADAccount'/span> -Name 'AllowPasswordReset'/span> -Value 1 -PropertyType DWord
}
}
uj5u.com熱心網友回復:
$verCheckOS = (Get-WmiObject win32_operatingsystem) .version
if ($verCheckOS -lt "10.0. 19043" -and $verCheckOS -gt "10.0.17134")
{
if (! (Test-Path "HKLM:SOFTWAREPoliciesMicrosoftAzureADAccount" ))
{
$null = New-Item -Name "AzureADAccount" -Path "HKLM:SOFTWAREPoliciesMicrosoft"
$null = New-ItemProperty -Path "HKLM:SOFTWAREPoliciesMicrosoftAzureADAccount" -Name "AllowPasswordReset" -Value 1 -PropertyType DWord
}
我對你的代碼感到有點困惑。 你檢查AzureADAccount鍵的完整路徑是否存在,然后如果它存在,你就繼續嘗試創建它? 我想你的意思是如果它不存在,那么就創建它? 我的意思是,如果它不存在,你的代碼就不會執行,所以創建它的那一行就會出錯。 所以我把它改成只有在路徑不存在的情況下才運行這個塊。 如果這是錯的,那么就把Test-Path行放回原處,并洗掉 "New-Item -Name "AzureADAccount "行,因為它沒有意義,保留New-ItemProperty行。
此外,只需在數字周圍添加引號即可使版本檢查陳述句在我的測驗中正常作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/326693.html
標籤:
