目前有这个,但它只报告带有chrome和版本的机器。我喜欢它也报告脱机的机器,或者更重要的是丢失文件。
任何提示
ta
$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 :(得分: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
答案 1 :(得分:0)
只需先检查机器是否可以到达,如果不是,请在文件中写入特殊条目。同样,如果找不到文件,只需写一个不同的条目:
$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"
}
}
显然你可能想要改变文字。也不是机器名的列有意义吗?