Powershell 用于从列表中扫描计算机并确定哪些计算机安装了软件标题的脚本
我已经把我的最终目标缩小了一点 我已经预先创建了要将结果写入的文件 下面是我想做的一个粗略脚本:Powershell 用于从列表中扫描计算机并确定哪些计算机安装了软件标题的脚本,powershell,Powershell,我已经把我的最终目标缩小了一点 我已经预先创建了要将结果写入的文件 下面是我想做的一个粗略脚本: $computers = Get-content "C:\users\nicholas.j.nedrow\desktop\scripts\lists\ComputerList.txt" # Ping all computers in ComputerList.txt. # Need WinEst_Computers.csv file created with 3 Colum
$computers = Get-content "C:\users\nicholas.j.nedrow\desktop\scripts\lists\ComputerList.txt"
# Ping all computers in ComputerList.txt.
# Need WinEst_Computers.csv file created with 3 Columns; Computer Name | Online (Y/N) | Does File Exist (Y/N)
$output = foreach ($comp in $computers) {
$TestConn = Test-connection -cn $comp -BufferSize 16 -Count 1 -ea 0 -quiet
if ($TestConn -match "False")
{
#Write "N" to "Online (Y/N)" Column in primary output .csv file
}
if ($TestConn -match "True")
{
#Write "Y" to "Online (Y/N)" Column in primary output .csv file
}
#For computers that return a "True" ping value:
#Search for WinEst.exe application on C:\
Get-ChildItem -Path "\\$comp\c$\program files (x86)\WinEst.exe" -ErrorAction SilentlyContinue |
if ("\\$comp\c$\program files (x86)\WinEst.exe" -match "False")
{
#Write "N" to "Does File Exist (Y/N)" Column in primary output .csv file
}
if ("\\$comp\c$\program files (x86)\WinEst.exe" -match "True")
{
#Write "Y" to "Does File Exist (Y/N)" Column in primary output .csv file
}
Select @{n='ComputerName';e={$comp}},Name
}
$output | Out-file "C:\users\nicholas.j.nedrow\desktop\scripts\results\CSV Files\WinEst_Computers.csv"
我需要以下方面的帮助:
$computer
是您的收藏,那么您当前的物品也不能是$computer
在您的foreach
中
Get Item
不返回属性computerName
。因此,您不能使用选择对象
显式选择它。但是,可以使用向输出的自定义对象添加新特性
如果您的CSV文件有一行标题,则使用Import CSV
读取文件更简单。如果它只是一个计算机名称列表,那么Get Content
工作得很好
如果您正在搜索单个文件,并且知道确切的路径,那么只需坚持使用-path
或-LiteralPath
并忘记-Include
<代码>-包含不直观,在在线文档中没有很好的解释
如果使用单个管道将输出管道化为导出Csv
,则无需使用-Append
,除非您已有一个包含要保留数据的现有Csv。但是,如果您选择在每个循环迭代期间通过管道导出Csv,则需要使用-Append
来保留输出
下面是一些使用建议的更新代码:
$computers = Get-content "C:\users\nicholas.j.nedrow\desktop\scripts\lists\ComputerList.txt"
$output = foreach ($comp in $computers) {
Get-Item -Path "\\$comp\c$\program files (x86)\WinEst.exe" -ErrorAction SilentlyContinue |
Select @{n='ComputerName';e={$comp}},Name
}
$output | Export-Csv -Path "C:\users\nicholas.j.nedrow\desktop\scripts\results\CSV Files\WinEst_Computers.csv" -NoType
您尚未告诉
导出Csv
cmdlet要导出什么。。。[咧嘴笑]现在就开始运行建议。将很快更新。谢谢你的帮助!看起来它运行时没有错误,但导出文件中没有任何信息。我假设这意味着我没有正确地传输输出?