[英]Script To find installed software
We are planning to write a script which will get all the software installed in the Windows system and compare with the list which we have listed and send the result by mail. 我们计划编写一个脚本,该脚本将获取Windows系统中安装的所有软件,并与我们列出的列表进行比较,并通过邮件发送结果。
I tried a lot and got the below script. 我做了很多尝试,并获得了以下脚本。 The issue is it wont get all the programs installed in the system.
问题是它不会在系统中安装所有程序。 Most of the software are missing and also compare is not working.
大多数软件都丢失,并且比较也无法正常工作。 Please help me to improve my script.
请帮助我改善脚本。
for /f "tokens=*" %%i in (D:\BatchScript\ListeProgs.txt) do echo %%i >>D:\BatchScript\newfile.txt
@echo off > D:\BatchScript\installed-programs.csv
regedit /e D:\BatchScript\regexport.txt "HKEY_LOCAL_MACHINE\Software\MicrosoftWindows\CurrentVersion\Uninstall"
find "DisplayName" < D:\BatchScript\regexport.txt > D:\BatchScript\regprogs.txt
for /f "tokens=enter code here2 delims==" %%a in (D:\BatchScript\regprogs.txt) do (
echo %%~a >>D:\BatchScript\installedprogs.txt )
for /f "tokens=*" %%L in (D:\BatchScript\installedprogs.txt) do (
call :sub1 %%L )
goto :eof
:sub1
>> installed-programs.csv echo %1,%2,%3,%4,%5,%6,%7,%8,%9
::== DONE
This is the script that will solve your problem. 这是可以解决您问题的脚本。
After running this code in Powershell you will get a function named Get-InstalledAppsDifferences
: 在Powershell中运行此代码后,您将获得一个名为
Get-InstalledAppsDifferences
的函数:
function Get-InstalledAppsDifferences {
Process {
Get-WmiObject -Class Win32_Product | Select-Object -Property Name | Sort-Object -Property Name -Unique > c:\LatestList.txt
IF (Test-Path C:\PreviousList.txt)
{
Compare-Object -ReferenceObject (Get-Content C:\latestList.txt) -DifferenceObject (Get-Content C:\PreviousList.txt) > "C:\Diff_$(get-date -f yyyy-MM-dd).txt"
Remove-Item C:\PreviousList.txt -Force
}
Move-Item C:\LatestList.txt C:\PreviousList.txt
}
}
To run the function inside powershell: 要在powershell中运行该功能:
Get-InstalledAppsDifferences
The function generates a list of currently installed programs in C:\\LatestList.txt
then looks for a file named C:\\PreviousList.txt
, if found generates differences and saves into a file name C:\\Diff_yyyy-mm-dd.txt
and removes the previous list. 该函数在
C:\\LatestList.txt
生成当前已安装程序的列表,然后查找名为C:\\PreviousList.txt
的文件(如果找到的话会生成差异并将其保存到文件名C:\\Diff_yyyy-mm-dd.txt
并且删除上一个列表。
At the end it renames LatestList.txt
to PreviousList.txt
for the next use. 最后,它将
LatestList.txt
重命名为PreviousList.txt
,以供下次使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.