PowerShell脚本环境变量

时间:2019-12-03 13:18:33

标签: bash performance powershell variables environment-variables

我需要配置脚本来验证“系统”环境变量“ LM_LICENSE_FILE”是否存在。如果存在,脚本还应验证该变量包括27000@test.university.com(代表LM指向的端口和服务器)作为变量中的值之一。在此变量中,值(如果存在)用逗号“,”分隔。最后,如果该值不存在,则此脚本还应执行修复。谁能帮助我指出正确的方向?

更新:这是我到目前为止的内容:

    if ((Get-ItemProperty -Path “HKLM:\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment”) -match “LM_LICENSES_FILE”) {write-host “yes”} else {write-host “no”}
$keyexists = ((Get-ItemProperty -Path “HKLM:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment”) -match “Path”)

if (-Not $keyexists)
    { New-ItemProperty -Path “HKLM:\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” -Name “LM_LICENSES_FILE” | New-ItemPropertyValue = “27000@test.university.edu”
  }

$valueexists = (Get-ItemProperty -Path “HKLM:\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\LM_LICENSES_FILE”)
if (-Not $valueexists)
    { Set-ItemPropertyValue -Name “LM_LICENSES_FILE” -Path “HKLM:\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\LM_LICENSES_FILE” -Value “27000@test.university.edu” -Force
    }

0 个答案:

没有答案