powershell - 将已安装的域计算机应用程序版本导出为 CSV - Chrome
问题描述
我正在尝试为我们网络上的工作站导出已安装的 Chrome 版本。我已将以下脚本放在一起,但遇到导出到 CSV 时出错的问题。任何建议将不胜感激。
Select-Object : Cannot convert System.Diagnostics.FileVersionInfo to one of the following types {System.String, System.Management.Automation.ScriptBlock}.
At line:22 char:14
Select-Object $computer, $Version | export-csv -Path c:\ ...
CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand
$computerlist = get-content C:\temp\computerlist.txt
foreach ($computer in $computerlist){
$test = 1
Write-Host "Testing connection to $computer..." -ForegroundColor Magenta
Try{
Test-Connection -Count 1 -ComputerName $computer -ErrorAction Stop | out-null
Write-Host "Connected!" -ForegroundColor Green
}
Catch{
Write-Host "Could not connect to $computer" -BackgroundColor Red -ForegroundColor Black
$test = 0
$computer | out-file c:\temp\badlist.txt
}
If ($test -eq 1){
ForEach($computer in $computerlist){
$computer = $computer
$Version = (Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe').'(Default)').VersionInfo
"$computer - $Version"
Out-String -InputObject $Version
Select-Object $computer, $Version | export-csv -Path c:\temp\Chromeversion$($date)-PS.csv -NoTypeInformation -Append
解决方案
Select-Object $computer, $Version
不能按预期工作,因为Select-Object
期望属性名称(或计算的属性)作为(位置隐含的)-Property
参数。
您正在传递valuesSystem.Diagnostics.FileVersionInfo
,它们被解释为名称,并且(存储在中的值的类型)的实例$Version
不被接受为name,这是错误消息所指示的。
为了得到你想要的,构造一个[pscustomobject]
如下:
[pscustomobject] @{ Computer = $computer; Version = $Version } |
Export-Csv -Path c:\temp\Chromeversion$($date)-PS.csv -NoTypeInformation -Append
推荐阅读
- scala - 为什么扩展 App 时没有初始化对象字段?
- twilio - Whatsapp 选择加入,选择加入审计
- machine-learning - 根据 F1、精度和召回分数计算准确度
- node.js - Mongo .save() 在本地工作,但在 Heroku 远程验证错误
- mongodb - MongoDB按嵌入式文档结构分组
- datastax-enterprise - DSE 6.7 Alwayson SQL
- ios - Swift 集合视图单元格大于集合视图框架
- prometheus - Alertmanager:在触发警报时向特定 URL 发送发布请求?
- html - 如何使浮动李的高度相等
- javascript - 如何从文件中删除属性?