2017-07-20 10 views
0

現在、これは持っていますが、chromeとバージョンのマシンのみを報告します。私はそれが好きだと、オフラインになっているマシン、あるいはもっと重要なことにファイルが欠落しているマシンも報告しています。レポートスクリプト。特定のファイルが欠けているマシンを報告したい

$Computers = Get-Adcomputer -Filter * 
foreach ($Computer in $Computers) 
{ 
$PC = $computer.dnshostname 
$hostname = $PC.split('.')[0] 
Write-Host "\\$PC\c`$\Program Files\Google\Chrome\Application\chrome.exe" 
$exe = "\\$pc\c`$\Program Files\Google\Chrome\Application\chrome.exe" 

if (Test-Path $exe){ 
    $ver = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($exe).FileVersion 
    Add-Content -path .\results.csv "$exe,$ver" 
} 

} 

答えて

0

TA

任意のヒントただマシンが最初に到達可能であるかどうかをチェックし、そうでない場合は、ファイルに特殊なエントリを書き込みます。同様に、ファイルが見つからない場合は、別のエントリを作成してください:

$Computers = Get-Adcomputer -Filter * 
foreach ($Computer in $Computers) 
{ 
    $PC = $computer.dnshostname 
    $hostname = $PC.split('.')[0] 
    if (Test-Connection $hostname -Count 1) { 
     Write-Host "\\$PC\c`$\Program Files\Google\Chrome\Application\chrome.exe" 
     $exe = "\\$pc\c`$\Program Files\Google\Chrome\Application\chrome.exe" 
     if (Test-Path $exe){ 
      $ver = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($exe).FileVersion 
      Add-Content -path .\results.csv "$exe,$ver" 
     } 
     else { 
      Add-Content -path .\results.csv "File not found" 
     } 
    } 
    else { 
     Add-Content -path .\results.csv "Not reachable" 
    } 
} 

明らかに、テキストを変更したい場合があります。また、機械名の列は意味をなさないでしょうか?

1

ホストが最初にアクセス可能かどうかを確認し、ホストが実際にオンラインである場合にのみファイルが存在するかどうかを確認します。ケースごとにカスタムオブジェクトを作成し、パイプラインを使用してそれらをCSVにエクスポートします。

$Computers | ForEach-Object { 
    $PC = $_.dnshostname 
    $exe = "\\$PC\C`$\Program Files\Google\Chrome\Application\chrome.exe" 

    if (Test-Connection $PC -Count 3 -Quiet) { 
     if (Test-Path -LiteralPath $exe){ 
      [PSCustomObject]@{ 
       Hostname = $PC 
       HostOnline = $true 
       FileExists = $true 
       FileVersion = [Diagnostics.FileVersionInfo]::GetVersionInfo($exe).FileVersion 
      } 
     } else { 
      [PSCustomObject]@{ 
       Hostname = $PC 
       HostOnline = $true 
       FileExists = $false 
       FileVersion = $null 
      } 
     } 
    } else { 
     [PSCustomObject]@{ 
      Hostname = $PC 
      HostOnline = $false 
      FileExists = $null 
      FileVersion = $null 
     } 
    } 
} | Export-Csv '.\results.csv' -NoType 
関連する問題