点击查看代码
![](/i/l/?n=22&i=blog/1326813/202210/1326813-20221002225935257-1660369632.png)
#1获取当前日期
$collect_date =Get-Date -Format "yyyy-MM-dd HH_mm"
#2获取计算机主机名
$ComputerName = hostname
#3定义需要查询的软件名称
$AppDisplayName= "Anyshare"
#4定义共享路径
#$Path1="\\10.128.32.102\share\Anyshare\"
#$Path2="\\172.16.14.200\share\Anyshare\"
$Path1="\\127.0.0.1\b站\temp\"
$Path2="\\127.0.0.1\b站\temp\"
#5查询MAC地址信息
$MacInfo=(getmac ) #获取MAC 地址列表
$i=3; #上面的命令从第三行开始才是有效MAC地址信息
#4查询软件的安装信息,并写入
Function Get-AppInfo($productDisplayname)
{
$Msg= $collect_date+":计算机"+$ComputerName+"未检测到软件"+$productDisplayname
$regPathX86 = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall'
$regPathX64 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
$regPath = ($regPathX64,$regPathX86)
Get-ChildItem ( foreach { $regPath})| foreach {
$product = Get-ItemProperty $_.PSPath
if($product.DisplayName -eq $productDisplayname)
{
$Msg=""
if((Test-Path $_.PSPath ))
{
$AppInfo = Get-ItemProperty $_.PSPath
if( $AppInfo.DisplayName -and $AppInfo.DisplayVersion)
{
$Msg= $collect_date+":," +$ComputerName+"," +$AppInfo.DisplayName +","+$AppInfo.DisplayVersion
}
}
}
}
#目标路径
$DisPath1= $Path1+$ComputerName+$collect_date +".txt"
$DisPath2= $Path2+$ComputerName+$collect_date +".txt"
$TempMessage=""
while($i -lt $MacInfo.Count ){
$TempMessage= $TempMessage+$Msg+','+$MacInfo[$i].Split()[0] +"`n" ;
Write-Host $TempMessage;
Write-Output $TempMessage|Out-File -filepath $DisPath1
Write-Output $TempMessage|Out-File -filepath $DisPath2
$i=$i+1
}
#Write-Host $Msg
}
Get-AppInfo $AppDisplayName