`#1获取当前日期
$collect_date =Get-Date -Format "yyyy-MM-dd HH_mm"
2获取计算机主机名
$ComputerName = hostname
3定义需要查询的软件名称
$AppDisplayName= "Anyshare1"
4定义共享路径
$Path="\127.0.0.1\b站\temp"
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
}
}
}
}
#目标路径
$DisPath= $Path+$ComputerName+$collect_date +".txt"
Write-Output $Msg|Out-File -filepath $DisPath
}
Get-AppInfo $AppDisplayName