点击查看代码
#样例
#文件路径
#C:\HEMS English Version\app\HEMS English Version.exe
#C:\Users\e03424\AppData\Local\HEMS English Version\app\HEMS English Version.exe
#注册表路径:
#计算机\HKEY_USERS\S-1-5-21-3354446880-2111472190-2361381164-1002\SOFTWARE\Feishu-cxmt
#定义基础信息
$Path="\\127.0.0.1\capture\"
$ComputerName = hostname
$collect_date =Get-Date -Format "yyyy-MM-dd HH_mm"
$DisPath= $Path+$ComputerName+"_HemsInfo.txt"
#根据文件路径获取文件属性
function get_fileInfo
{
param($file_path="")
$fileInfo = Get-Item $file_path
$data_source="File"
$file_Path=$file_path
$file_DataDir="未知"
$file_Version=$fileInfo.VersionInfo.ProductVersion
$file_CreationTime=$fileInfo.CreationTime
$Msg=$collect_date+":"+$ComputerName+"|" +$data_source+"|" +$file_Path+"|" +$file_DataDir+"|" +$file_Version+"|" +$file_CreationTime
#Write-Host $Msg
Write-Output $Msg|Out-File -filepath $DisPath -Append
}
#测试用例
#get_fileInfo "C:\HEMS English Version\app\HEMS English Version.exe"
#根据注册表信息获取文件Hems 属性
function get_reginfo
{
param($reg_path="")
$reg_res=Get-ItemProperty -Path $reg_path
$data_source="reg"
$file_Path=$reg_res.InstallDir+"\"+$reg_res.ExeFileName
$file_DataDir=$reg_res.DataDir
$file_Version=$reg_res.Version
$file_CreationTime="未知"
$Msg=$collect_date+":"+$ComputerName+"|" +$data_source+"|" +$file_Path+"|" +$file_DataDir+"|" +$file_Version+"|" +$file_CreationTime
#Write-Host $Msg
Write-Output $Msg|Out-File -filepath $DisPath -Append
}
#测试用例
#get_reginfo "Registry::HKEY_USERS\S-1-5-21-3354446880-2111472190-2361381164-1002\SOFTWARE\Feishu-cxmt"
#任务1:执行循环 获取注册表信息
foreach ($item in (Get-childItem -Path "Registry::HKEY_USERS\"))
{
# 仅取属于用户得注册表信息
if ($item.Name.Length -eq 57)
{
#判断 注册表路径是否存在
$reg_path= "Registry::HKEY_USERS\" +$item.PSChildName + "\SOFTWARE\Feishu-cxmt"
if((Test-Path $reg_path))
{
get_reginfo $reg_path
}
}
}
#任务2:执行循环 获取文件路径信息
foreach ($item in (Get-childItem -Path "C:\Users\"))
{
#判断 注册表路径是否存在
$file_path= "C:\Users\" +$item.Name + "\AppData\Local\HEMS English Version\app\HEMS English Version.exe"
if((Test-Path $file_path))
{
get_fileInfo $file_path
}
}
#任务3:查询 C 盘根目录下面文件
$Temporary_Path = "C:\HEMS English Version\app\HEMS English Version.exe"
if((Test-Path $Temporary_Path))
{
get_fileInfo $Temporary_Path
}