Powershell Script Running Slowly

前端 未结 4 1414
眼角桃花
眼角桃花 2021-01-28 07:46

I\'m writing a script to check the version on about 15 remote servers and the script is taking much longer to execute than I would expect.

$listServers = @(\"com         


        
4条回答
  •  孤城傲影
    2021-01-28 08:28

    Queries against Win32_Product trigger a reconfiguration of installed packages, which is what makes the process so time-consuming. It also makes such queries potentially harmful, since it may inadvertently reset configuration parameters.

    For something like a version check on a particular program you're better off reading the information directly from the (remote) registry:

    $listServers | % {
      $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $_)
      $key = $reg.OpenSubKey('SOFTWARE\JavaSoft\Java Runtime Environment')
      New-Object -Type PSObject -Property @{
        'Server'      = $_
        'JavaVersion' = $key.GetValue('CurrentVersion')
      }
    } | Export-Csv 'C:\temp\javaVersion.csv' -NoType
    

提交回复
热议问题