Dear forum readers,
I like to make a software inventory per computer in a Microsoft Domain, but I also like to exclude some data from this collection (general information such as Microsoft, Intel drivers and so on).
In pseudo code, I like to achieve the following with my script:
- Read all computernames that are stored in a central text file c:\temp\computers.txt
- Make a software inventory per computer name that are mentioned in that central file → c:\temp\computers.txt
- Exclude keywords that are stored (per line) in an External file. For example: (c:\temp\File_with_to_be_excluded_keywords.txt
- Put all collected data in an Excel sheet (per tab the data of the collected information)
The script mentioned below works, but it doesn’t use the 2 files mentioned above as an input source.
It also does not add several tabs with the computername and the found software.
Please check the comments that I put in the script mentioned below (between de dashed line).
Thank you in advance for you help/support
type or paste code here
Cls
#----------------------------------------------------------------------------------------------------------------------
# I would like to read a text file that will contains several computernames to start inventorizing software
# (on computername per line). Not using the array below
#----------------------------------------------------------------------------------------------------------------------
# $computernames = "Computername1" # ,"computername2","computername3"
#----------------------------------------------------------------------------------------------------------------------
$array = @()
foreach($computername in $computernames){
$UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" #Define the variable to hold the location of Currently Installed Programs
$reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computername) #Create an instance of the Registry Object and open the HKLM base key
$regkey=$reg.OpenSubKey($UninstallKey) #Drill down into the Uninstall key using the OpenSubKey Method
$subkeys=$regkey.GetSubKeyNames() #Retrieve an array of string that contain all the subkey names
foreach($key in $subkeys){
$thisKey=$UninstallKey+"\\"+$key
$thisSubKey=$reg.OpenSubKey($thisKey)
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
#----------------------------------------------------------------------------------------------------------------------
# I would like to use a file that contains keywords that will exclude information from the generated output file.
# For example: C:\temp\Exclude_This_Keywords_from_filter.txt
# Context of the file could be (per line a keyword) -> Intel, Microsoft, ...
# So not using the statement mentioned below
#----------------------------------------------------------------------------------------------------------------------
if($obj -like "*Microsoft*" -or $obj -like "*Intel*" -or $obj -like "*Dell*" -or $obj -like "*Something else*"){}else{
$array += $obj
}
}
}
echo $array
#----------------------------------------------------------------------------------------------------------------------
# Last and least: I would like to add new tabs (Excel) that saves the computername as a tab and that includes all rows with the collected software inventory
#----------------------------------------------------------------------------------------------------------------------
$array | Where-Object { $_.DisplayName } | select DisplayName | ft -auto > c:\temp\$computername.csv