我让 PowerShell 脚本在我们网络上的所有 PC 上运行,并从 PC 获取信息并将其保存在 CSV 文件中,并每次使用新 PC 作为新行更新文件。
$logData = @(
[pscustomobject]@{
ComputerName = $ComputerName
IPAddress = $env:HostIP
User = $User
Email = $Email
ProgramsInstalled = $ProgramsInstalled
}
)
$logData | Export-Csv $csv -Encoding UTF8 -Append -NoTypeInformation -Force
我使用此代码来获取电脑上安装的所有软件
$ProgramsInstalled = (Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*','HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*') | Select-Object DisplayName
我没有获得所有软件,但当我单独运行它并将其保存在 csv 文件中时,我连续获得了每个软件。
我希望它们分组在一个单元格中
This...
(Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*','HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*') | Select-Object DisplayName
...带回一个数组。
如果您希望将其放在单个列中,那么您必须连接数组结果。
$ProgramsInstalled = Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' |
Select-Object -Property DisplayName
# Results
<#
DisplayName
-----------
SAPIEN Document Explorer 2020
GIMP 2.10.14
Git version 2.24.0.2
...
#>
$ProgramsInstalled = ((Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' |
Select-Object -Property DisplayName)).DisplayName -join ','
# Results
<#
SAPIEN Document Explorer 2020,GIMP 2.10.14,Git version 2.24.0.2,...
#>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)