Trying to develop auditing program
I've compiled this auditing program a while back when I was working as an IT for my local university and I'm quite stuck with actually grabbing the current working drive and pulling all of the files from Programs and Programs x86 to successfully to build this application, instead of using the registry (SOFTWAREMicrosoftWindowsCurrentVersionUninstall) because that doesn't pull all of the programs only some.
Also, I'm unsure of how about getting the current active directory drive where the script is located originally on the second bolded part and make a folder in which it saves the file as the msinfo32.exe system name into a new folder.
(It doesn't matter what the name is) this is a long-term goal in which I have been trying to accomplish and I'm absolutely lost.
' Sample VBScript to Export list of Installed Programs into CSV File.
' ------------------------------------------------------
const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strKeyPath
strComputer = "."
' Registry key path of Control panel items for installed programs
strKeyPath = "SOFTWAREMicrosoftWindowsCurrentVersionUninstall"
Dim objReg, strSubkey, arrSubkeys
Set objReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\" & _
strComputer & "rootdefault:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
Dim objFSO, objCSVFile
' Create CSV file
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Here, I have given CSV file path as "Installed-Softwares.csv", this will create Installed-Softwares.csv file
' where you placed and execute this VB Script file. You can give your own file path
' like "C:UsersAdministratorDesktopInstalled-Softwares.csv"
Set objCSVFile = objFSO.CreateTextFile("F:CustomInstalled-Softwares.csv", _
ForWriting, True)**
' Write Software property names as CSV columns(first line)
objCSVFile.Write "Name,Version,Publisher,Location,Size"
objCSVFile.Writeline ' New Line
Dim Name,Version,Publisher,Location,Size
'Enumerate registry keys.
For Each strSubkey In arrSubkeys
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayName" , Name
If Name <> "" Then
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayVersion", Version
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "Publisher",Publisher
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "InstallLocation", Location
objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "EstimatedSize" , Size
If Size <> "" Then
Size= Round(Size/1024, 3) & " MB"
Else
Size= "0 MB"
End If
objCSVFile.Write Name &","&Version&","&Publisher&","&Location&","&Size
objCSVFile.Writeline ' New Line
End If
Next
WScript.Quit
Comment: For example, pull from (C: for example or current main drive) program files and program files x86 -> put into list -> output Currentdrive:newfoldermsinfo32systemname.
Also, it's displaying 0 MB instead of the actual MB, I noticed the output file is doing this. This works in conjuction with other files, in no means did I actually code this entirely from scratch.
Credit: https://www.morgantechspace.com/2014/04/VBScript-to-Get-List-of-Installed-Software-through-Registry.html
powershell csv vbscript audit
add a comment |
I've compiled this auditing program a while back when I was working as an IT for my local university and I'm quite stuck with actually grabbing the current working drive and pulling all of the files from Programs and Programs x86 to successfully to build this application, instead of using the registry (SOFTWAREMicrosoftWindowsCurrentVersionUninstall) because that doesn't pull all of the programs only some.
Also, I'm unsure of how about getting the current active directory drive where the script is located originally on the second bolded part and make a folder in which it saves the file as the msinfo32.exe system name into a new folder.
(It doesn't matter what the name is) this is a long-term goal in which I have been trying to accomplish and I'm absolutely lost.
' Sample VBScript to Export list of Installed Programs into CSV File.
' ------------------------------------------------------
const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strKeyPath
strComputer = "."
' Registry key path of Control panel items for installed programs
strKeyPath = "SOFTWAREMicrosoftWindowsCurrentVersionUninstall"
Dim objReg, strSubkey, arrSubkeys
Set objReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\" & _
strComputer & "rootdefault:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
Dim objFSO, objCSVFile
' Create CSV file
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Here, I have given CSV file path as "Installed-Softwares.csv", this will create Installed-Softwares.csv file
' where you placed and execute this VB Script file. You can give your own file path
' like "C:UsersAdministratorDesktopInstalled-Softwares.csv"
Set objCSVFile = objFSO.CreateTextFile("F:CustomInstalled-Softwares.csv", _
ForWriting, True)**
' Write Software property names as CSV columns(first line)
objCSVFile.Write "Name,Version,Publisher,Location,Size"
objCSVFile.Writeline ' New Line
Dim Name,Version,Publisher,Location,Size
'Enumerate registry keys.
For Each strSubkey In arrSubkeys
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayName" , Name
If Name <> "" Then
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayVersion", Version
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "Publisher",Publisher
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "InstallLocation", Location
objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "EstimatedSize" , Size
If Size <> "" Then
Size= Round(Size/1024, 3) & " MB"
Else
Size= "0 MB"
End If
objCSVFile.Write Name &","&Version&","&Publisher&","&Location&","&Size
objCSVFile.Writeline ' New Line
End If
Next
WScript.Quit
Comment: For example, pull from (C: for example or current main drive) program files and program files x86 -> put into list -> output Currentdrive:newfoldermsinfo32systemname.
Also, it's displaying 0 MB instead of the actual MB, I noticed the output file is doing this. This works in conjuction with other files, in no means did I actually code this entirely from scratch.
Credit: https://www.morgantechspace.com/2014/04/VBScript-to-Get-List-of-Installed-Software-through-Registry.html
powershell csv vbscript audit
If you're using PSv5+, can you not just use something likeGet-Package | Sort Name | Export-Csv C:tempinstalledItems.csv -NoTypeInformation
?
– trebleCode
Nov 21 '18 at 14:01
As for theSize
issue:objReg.GetDWORDValue
gets a numeric value. You are comparing it to a string withIf Size <> "" Then
. Change that toIf Size <> 0 Then
.
– Theo
Nov 21 '18 at 15:00
add a comment |
I've compiled this auditing program a while back when I was working as an IT for my local university and I'm quite stuck with actually grabbing the current working drive and pulling all of the files from Programs and Programs x86 to successfully to build this application, instead of using the registry (SOFTWAREMicrosoftWindowsCurrentVersionUninstall) because that doesn't pull all of the programs only some.
Also, I'm unsure of how about getting the current active directory drive where the script is located originally on the second bolded part and make a folder in which it saves the file as the msinfo32.exe system name into a new folder.
(It doesn't matter what the name is) this is a long-term goal in which I have been trying to accomplish and I'm absolutely lost.
' Sample VBScript to Export list of Installed Programs into CSV File.
' ------------------------------------------------------
const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strKeyPath
strComputer = "."
' Registry key path of Control panel items for installed programs
strKeyPath = "SOFTWAREMicrosoftWindowsCurrentVersionUninstall"
Dim objReg, strSubkey, arrSubkeys
Set objReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\" & _
strComputer & "rootdefault:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
Dim objFSO, objCSVFile
' Create CSV file
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Here, I have given CSV file path as "Installed-Softwares.csv", this will create Installed-Softwares.csv file
' where you placed and execute this VB Script file. You can give your own file path
' like "C:UsersAdministratorDesktopInstalled-Softwares.csv"
Set objCSVFile = objFSO.CreateTextFile("F:CustomInstalled-Softwares.csv", _
ForWriting, True)**
' Write Software property names as CSV columns(first line)
objCSVFile.Write "Name,Version,Publisher,Location,Size"
objCSVFile.Writeline ' New Line
Dim Name,Version,Publisher,Location,Size
'Enumerate registry keys.
For Each strSubkey In arrSubkeys
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayName" , Name
If Name <> "" Then
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayVersion", Version
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "Publisher",Publisher
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "InstallLocation", Location
objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "EstimatedSize" , Size
If Size <> "" Then
Size= Round(Size/1024, 3) & " MB"
Else
Size= "0 MB"
End If
objCSVFile.Write Name &","&Version&","&Publisher&","&Location&","&Size
objCSVFile.Writeline ' New Line
End If
Next
WScript.Quit
Comment: For example, pull from (C: for example or current main drive) program files and program files x86 -> put into list -> output Currentdrive:newfoldermsinfo32systemname.
Also, it's displaying 0 MB instead of the actual MB, I noticed the output file is doing this. This works in conjuction with other files, in no means did I actually code this entirely from scratch.
Credit: https://www.morgantechspace.com/2014/04/VBScript-to-Get-List-of-Installed-Software-through-Registry.html
powershell csv vbscript audit
I've compiled this auditing program a while back when I was working as an IT for my local university and I'm quite stuck with actually grabbing the current working drive and pulling all of the files from Programs and Programs x86 to successfully to build this application, instead of using the registry (SOFTWAREMicrosoftWindowsCurrentVersionUninstall) because that doesn't pull all of the programs only some.
Also, I'm unsure of how about getting the current active directory drive where the script is located originally on the second bolded part and make a folder in which it saves the file as the msinfo32.exe system name into a new folder.
(It doesn't matter what the name is) this is a long-term goal in which I have been trying to accomplish and I'm absolutely lost.
' Sample VBScript to Export list of Installed Programs into CSV File.
' ------------------------------------------------------
const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strKeyPath
strComputer = "."
' Registry key path of Control panel items for installed programs
strKeyPath = "SOFTWAREMicrosoftWindowsCurrentVersionUninstall"
Dim objReg, strSubkey, arrSubkeys
Set objReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\" & _
strComputer & "rootdefault:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
Dim objFSO, objCSVFile
' Create CSV file
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Here, I have given CSV file path as "Installed-Softwares.csv", this will create Installed-Softwares.csv file
' where you placed and execute this VB Script file. You can give your own file path
' like "C:UsersAdministratorDesktopInstalled-Softwares.csv"
Set objCSVFile = objFSO.CreateTextFile("F:CustomInstalled-Softwares.csv", _
ForWriting, True)**
' Write Software property names as CSV columns(first line)
objCSVFile.Write "Name,Version,Publisher,Location,Size"
objCSVFile.Writeline ' New Line
Dim Name,Version,Publisher,Location,Size
'Enumerate registry keys.
For Each strSubkey In arrSubkeys
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayName" , Name
If Name <> "" Then
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayVersion", Version
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "Publisher",Publisher
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "InstallLocation", Location
objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "EstimatedSize" , Size
If Size <> "" Then
Size= Round(Size/1024, 3) & " MB"
Else
Size= "0 MB"
End If
objCSVFile.Write Name &","&Version&","&Publisher&","&Location&","&Size
objCSVFile.Writeline ' New Line
End If
Next
WScript.Quit
Comment: For example, pull from (C: for example or current main drive) program files and program files x86 -> put into list -> output Currentdrive:newfoldermsinfo32systemname.
Also, it's displaying 0 MB instead of the actual MB, I noticed the output file is doing this. This works in conjuction with other files, in no means did I actually code this entirely from scratch.
Credit: https://www.morgantechspace.com/2014/04/VBScript-to-Get-List-of-Installed-Software-through-Registry.html
powershell csv vbscript audit
powershell csv vbscript audit
edited Nov 21 '18 at 14:13
Perfect.exe
asked Nov 21 '18 at 13:23
Perfect.exePerfect.exe
13
13
If you're using PSv5+, can you not just use something likeGet-Package | Sort Name | Export-Csv C:tempinstalledItems.csv -NoTypeInformation
?
– trebleCode
Nov 21 '18 at 14:01
As for theSize
issue:objReg.GetDWORDValue
gets a numeric value. You are comparing it to a string withIf Size <> "" Then
. Change that toIf Size <> 0 Then
.
– Theo
Nov 21 '18 at 15:00
add a comment |
If you're using PSv5+, can you not just use something likeGet-Package | Sort Name | Export-Csv C:tempinstalledItems.csv -NoTypeInformation
?
– trebleCode
Nov 21 '18 at 14:01
As for theSize
issue:objReg.GetDWORDValue
gets a numeric value. You are comparing it to a string withIf Size <> "" Then
. Change that toIf Size <> 0 Then
.
– Theo
Nov 21 '18 at 15:00
If you're using PSv5+, can you not just use something like
Get-Package | Sort Name | Export-Csv C:tempinstalledItems.csv -NoTypeInformation
?– trebleCode
Nov 21 '18 at 14:01
If you're using PSv5+, can you not just use something like
Get-Package | Sort Name | Export-Csv C:tempinstalledItems.csv -NoTypeInformation
?– trebleCode
Nov 21 '18 at 14:01
As for the
Size
issue: objReg.GetDWORDValue
gets a numeric value. You are comparing it to a string with If Size <> "" Then
. Change that to If Size <> 0 Then
.– Theo
Nov 21 '18 at 15:00
As for the
Size
issue: objReg.GetDWORDValue
gets a numeric value. You are comparing it to a string with If Size <> "" Then
. Change that to If Size <> 0 Then
.– Theo
Nov 21 '18 at 15:00
add a comment |
1 Answer
1
active
oldest
votes
Since you are tagging this as Powershell, here's a function you can use to find installed software on (remote) computer(s). It uses the registry, but looks for software in both SOFTWAREMicrosoftWindowsCurrentVersionUninstall
and SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall
.
# Get the current path this script is in
$ScriptPath = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path $script:MyInvocation.MyCommand.Path }
# Combine to make a valid path for the output file
$OutputPath = Join-Path -Path $ScriptPath -ChildPath 'InstalledSoftware'
if (!(Test-Path -Path $OutputPath -PathType Container)) {
New-Item -Path $OutputPath -ItemType Directory -Force | Out-Null
}
function Get-InstalledSoftware {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[string]$ComputerName = $env:COMPUTERNAME,
[Parameter(Mandatory = $false)]
[string]$NamePattern = '*',
[switch]$ExcludeUpdates
)
begin {
$UninstallPaths = 'SOFTWAREMicrosoftWindowsCurrentVersionUninstall',
'SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall'
}
process {
foreach ($computer in $ComputerName) {
$result = @()
if ([string]::IsNullOrEmpty($computer) -or $computer -eq '.') { $computer = $env:COMPUTERNAME }
$loggedOnUser = (Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer).UserName
$regBaseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$computer)
foreach ($regPath in $UninstallPaths) {
($regBaseKey.OpenSubKey($regPath)) | foreach {
$_.GetSubKeyNames() | ForEach-Object {
$regSubKey = $regBaseKey.OpenSubKey("$regPath$_")
$application = $regSubKey.GetValue('DisplayName')
$size = [int64]$regSubKey.GetValue('EstimatedSize')
if (($application) -and ($application -like $NamePattern)) {
if (!$ExcludeUpdates -or ($application -notlike "*update*")) {
$result += [PSCustomObject]@{
'Computer' = $computer
'Application' = $application
'Version' = $regSubKey.GetValue('DisplayVersion')
'InstallLocation' = $regSubKey.GetValue('InstallLocation')
'UninstallString' = $regSubKey.GetValue('UninstallString')
'Publisher' = $regSubKey.GetValue('Publisher')
'Size' = '{0:F2} MB' -f ($size / 1MB)
'LoggedOnUser' = $loggedOnUser
}
}
}
# close $regSubKey
if ($regSubKey) { $regSubKey.Close() }
}
}
}
# close $regBaseKey
if ($regBaseKey) { $regBaseKey.Close() }
# export the software list for this computer as CSV
$outputFile = Join-Path -Path $OutputPath -ChildPath "msinfo32$computer"
($result | Sort-Object -Property 'Application' -Unique) | Export-Csv -Path $outputFile -NoTypeInformation
# show on screen
Write-Verbose "Created '$outputFile'"
}
}
}
It creates a folder in the current script path called 'InstalledSoftware' where the csv file per computer is saved as 'msinfo32COMPUTERNAME.csv'
Call it like this for the local computer:
Get-InstalledSoftware -NamePattern * -ExcludeUpdates -Verbose
or feed it an array of computer names (you have admin permissions on) like this:
Get-InstalledSoftware -ComputerName machine1,machine2,machine3 -NamePattern * -ExcludeUpdates -Verbose
@Perfect.exe If you find my answer has helped you, then feel free to accepting the answer
– Theo
Dec 1 '18 at 10:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413013%2ftrying-to-develop-auditing-program%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since you are tagging this as Powershell, here's a function you can use to find installed software on (remote) computer(s). It uses the registry, but looks for software in both SOFTWAREMicrosoftWindowsCurrentVersionUninstall
and SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall
.
# Get the current path this script is in
$ScriptPath = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path $script:MyInvocation.MyCommand.Path }
# Combine to make a valid path for the output file
$OutputPath = Join-Path -Path $ScriptPath -ChildPath 'InstalledSoftware'
if (!(Test-Path -Path $OutputPath -PathType Container)) {
New-Item -Path $OutputPath -ItemType Directory -Force | Out-Null
}
function Get-InstalledSoftware {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[string]$ComputerName = $env:COMPUTERNAME,
[Parameter(Mandatory = $false)]
[string]$NamePattern = '*',
[switch]$ExcludeUpdates
)
begin {
$UninstallPaths = 'SOFTWAREMicrosoftWindowsCurrentVersionUninstall',
'SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall'
}
process {
foreach ($computer in $ComputerName) {
$result = @()
if ([string]::IsNullOrEmpty($computer) -or $computer -eq '.') { $computer = $env:COMPUTERNAME }
$loggedOnUser = (Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer).UserName
$regBaseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$computer)
foreach ($regPath in $UninstallPaths) {
($regBaseKey.OpenSubKey($regPath)) | foreach {
$_.GetSubKeyNames() | ForEach-Object {
$regSubKey = $regBaseKey.OpenSubKey("$regPath$_")
$application = $regSubKey.GetValue('DisplayName')
$size = [int64]$regSubKey.GetValue('EstimatedSize')
if (($application) -and ($application -like $NamePattern)) {
if (!$ExcludeUpdates -or ($application -notlike "*update*")) {
$result += [PSCustomObject]@{
'Computer' = $computer
'Application' = $application
'Version' = $regSubKey.GetValue('DisplayVersion')
'InstallLocation' = $regSubKey.GetValue('InstallLocation')
'UninstallString' = $regSubKey.GetValue('UninstallString')
'Publisher' = $regSubKey.GetValue('Publisher')
'Size' = '{0:F2} MB' -f ($size / 1MB)
'LoggedOnUser' = $loggedOnUser
}
}
}
# close $regSubKey
if ($regSubKey) { $regSubKey.Close() }
}
}
}
# close $regBaseKey
if ($regBaseKey) { $regBaseKey.Close() }
# export the software list for this computer as CSV
$outputFile = Join-Path -Path $OutputPath -ChildPath "msinfo32$computer"
($result | Sort-Object -Property 'Application' -Unique) | Export-Csv -Path $outputFile -NoTypeInformation
# show on screen
Write-Verbose "Created '$outputFile'"
}
}
}
It creates a folder in the current script path called 'InstalledSoftware' where the csv file per computer is saved as 'msinfo32COMPUTERNAME.csv'
Call it like this for the local computer:
Get-InstalledSoftware -NamePattern * -ExcludeUpdates -Verbose
or feed it an array of computer names (you have admin permissions on) like this:
Get-InstalledSoftware -ComputerName machine1,machine2,machine3 -NamePattern * -ExcludeUpdates -Verbose
@Perfect.exe If you find my answer has helped you, then feel free to accepting the answer
– Theo
Dec 1 '18 at 10:58
add a comment |
Since you are tagging this as Powershell, here's a function you can use to find installed software on (remote) computer(s). It uses the registry, but looks for software in both SOFTWAREMicrosoftWindowsCurrentVersionUninstall
and SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall
.
# Get the current path this script is in
$ScriptPath = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path $script:MyInvocation.MyCommand.Path }
# Combine to make a valid path for the output file
$OutputPath = Join-Path -Path $ScriptPath -ChildPath 'InstalledSoftware'
if (!(Test-Path -Path $OutputPath -PathType Container)) {
New-Item -Path $OutputPath -ItemType Directory -Force | Out-Null
}
function Get-InstalledSoftware {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[string]$ComputerName = $env:COMPUTERNAME,
[Parameter(Mandatory = $false)]
[string]$NamePattern = '*',
[switch]$ExcludeUpdates
)
begin {
$UninstallPaths = 'SOFTWAREMicrosoftWindowsCurrentVersionUninstall',
'SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall'
}
process {
foreach ($computer in $ComputerName) {
$result = @()
if ([string]::IsNullOrEmpty($computer) -or $computer -eq '.') { $computer = $env:COMPUTERNAME }
$loggedOnUser = (Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer).UserName
$regBaseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$computer)
foreach ($regPath in $UninstallPaths) {
($regBaseKey.OpenSubKey($regPath)) | foreach {
$_.GetSubKeyNames() | ForEach-Object {
$regSubKey = $regBaseKey.OpenSubKey("$regPath$_")
$application = $regSubKey.GetValue('DisplayName')
$size = [int64]$regSubKey.GetValue('EstimatedSize')
if (($application) -and ($application -like $NamePattern)) {
if (!$ExcludeUpdates -or ($application -notlike "*update*")) {
$result += [PSCustomObject]@{
'Computer' = $computer
'Application' = $application
'Version' = $regSubKey.GetValue('DisplayVersion')
'InstallLocation' = $regSubKey.GetValue('InstallLocation')
'UninstallString' = $regSubKey.GetValue('UninstallString')
'Publisher' = $regSubKey.GetValue('Publisher')
'Size' = '{0:F2} MB' -f ($size / 1MB)
'LoggedOnUser' = $loggedOnUser
}
}
}
# close $regSubKey
if ($regSubKey) { $regSubKey.Close() }
}
}
}
# close $regBaseKey
if ($regBaseKey) { $regBaseKey.Close() }
# export the software list for this computer as CSV
$outputFile = Join-Path -Path $OutputPath -ChildPath "msinfo32$computer"
($result | Sort-Object -Property 'Application' -Unique) | Export-Csv -Path $outputFile -NoTypeInformation
# show on screen
Write-Verbose "Created '$outputFile'"
}
}
}
It creates a folder in the current script path called 'InstalledSoftware' where the csv file per computer is saved as 'msinfo32COMPUTERNAME.csv'
Call it like this for the local computer:
Get-InstalledSoftware -NamePattern * -ExcludeUpdates -Verbose
or feed it an array of computer names (you have admin permissions on) like this:
Get-InstalledSoftware -ComputerName machine1,machine2,machine3 -NamePattern * -ExcludeUpdates -Verbose
@Perfect.exe If you find my answer has helped you, then feel free to accepting the answer
– Theo
Dec 1 '18 at 10:58
add a comment |
Since you are tagging this as Powershell, here's a function you can use to find installed software on (remote) computer(s). It uses the registry, but looks for software in both SOFTWAREMicrosoftWindowsCurrentVersionUninstall
and SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall
.
# Get the current path this script is in
$ScriptPath = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path $script:MyInvocation.MyCommand.Path }
# Combine to make a valid path for the output file
$OutputPath = Join-Path -Path $ScriptPath -ChildPath 'InstalledSoftware'
if (!(Test-Path -Path $OutputPath -PathType Container)) {
New-Item -Path $OutputPath -ItemType Directory -Force | Out-Null
}
function Get-InstalledSoftware {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[string]$ComputerName = $env:COMPUTERNAME,
[Parameter(Mandatory = $false)]
[string]$NamePattern = '*',
[switch]$ExcludeUpdates
)
begin {
$UninstallPaths = 'SOFTWAREMicrosoftWindowsCurrentVersionUninstall',
'SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall'
}
process {
foreach ($computer in $ComputerName) {
$result = @()
if ([string]::IsNullOrEmpty($computer) -or $computer -eq '.') { $computer = $env:COMPUTERNAME }
$loggedOnUser = (Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer).UserName
$regBaseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$computer)
foreach ($regPath in $UninstallPaths) {
($regBaseKey.OpenSubKey($regPath)) | foreach {
$_.GetSubKeyNames() | ForEach-Object {
$regSubKey = $regBaseKey.OpenSubKey("$regPath$_")
$application = $regSubKey.GetValue('DisplayName')
$size = [int64]$regSubKey.GetValue('EstimatedSize')
if (($application) -and ($application -like $NamePattern)) {
if (!$ExcludeUpdates -or ($application -notlike "*update*")) {
$result += [PSCustomObject]@{
'Computer' = $computer
'Application' = $application
'Version' = $regSubKey.GetValue('DisplayVersion')
'InstallLocation' = $regSubKey.GetValue('InstallLocation')
'UninstallString' = $regSubKey.GetValue('UninstallString')
'Publisher' = $regSubKey.GetValue('Publisher')
'Size' = '{0:F2} MB' -f ($size / 1MB)
'LoggedOnUser' = $loggedOnUser
}
}
}
# close $regSubKey
if ($regSubKey) { $regSubKey.Close() }
}
}
}
# close $regBaseKey
if ($regBaseKey) { $regBaseKey.Close() }
# export the software list for this computer as CSV
$outputFile = Join-Path -Path $OutputPath -ChildPath "msinfo32$computer"
($result | Sort-Object -Property 'Application' -Unique) | Export-Csv -Path $outputFile -NoTypeInformation
# show on screen
Write-Verbose "Created '$outputFile'"
}
}
}
It creates a folder in the current script path called 'InstalledSoftware' where the csv file per computer is saved as 'msinfo32COMPUTERNAME.csv'
Call it like this for the local computer:
Get-InstalledSoftware -NamePattern * -ExcludeUpdates -Verbose
or feed it an array of computer names (you have admin permissions on) like this:
Get-InstalledSoftware -ComputerName machine1,machine2,machine3 -NamePattern * -ExcludeUpdates -Verbose
Since you are tagging this as Powershell, here's a function you can use to find installed software on (remote) computer(s). It uses the registry, but looks for software in both SOFTWAREMicrosoftWindowsCurrentVersionUninstall
and SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall
.
# Get the current path this script is in
$ScriptPath = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path $script:MyInvocation.MyCommand.Path }
# Combine to make a valid path for the output file
$OutputPath = Join-Path -Path $ScriptPath -ChildPath 'InstalledSoftware'
if (!(Test-Path -Path $OutputPath -PathType Container)) {
New-Item -Path $OutputPath -ItemType Directory -Force | Out-Null
}
function Get-InstalledSoftware {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[string]$ComputerName = $env:COMPUTERNAME,
[Parameter(Mandatory = $false)]
[string]$NamePattern = '*',
[switch]$ExcludeUpdates
)
begin {
$UninstallPaths = 'SOFTWAREMicrosoftWindowsCurrentVersionUninstall',
'SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall'
}
process {
foreach ($computer in $ComputerName) {
$result = @()
if ([string]::IsNullOrEmpty($computer) -or $computer -eq '.') { $computer = $env:COMPUTERNAME }
$loggedOnUser = (Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer).UserName
$regBaseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$computer)
foreach ($regPath in $UninstallPaths) {
($regBaseKey.OpenSubKey($regPath)) | foreach {
$_.GetSubKeyNames() | ForEach-Object {
$regSubKey = $regBaseKey.OpenSubKey("$regPath$_")
$application = $regSubKey.GetValue('DisplayName')
$size = [int64]$regSubKey.GetValue('EstimatedSize')
if (($application) -and ($application -like $NamePattern)) {
if (!$ExcludeUpdates -or ($application -notlike "*update*")) {
$result += [PSCustomObject]@{
'Computer' = $computer
'Application' = $application
'Version' = $regSubKey.GetValue('DisplayVersion')
'InstallLocation' = $regSubKey.GetValue('InstallLocation')
'UninstallString' = $regSubKey.GetValue('UninstallString')
'Publisher' = $regSubKey.GetValue('Publisher')
'Size' = '{0:F2} MB' -f ($size / 1MB)
'LoggedOnUser' = $loggedOnUser
}
}
}
# close $regSubKey
if ($regSubKey) { $regSubKey.Close() }
}
}
}
# close $regBaseKey
if ($regBaseKey) { $regBaseKey.Close() }
# export the software list for this computer as CSV
$outputFile = Join-Path -Path $OutputPath -ChildPath "msinfo32$computer"
($result | Sort-Object -Property 'Application' -Unique) | Export-Csv -Path $outputFile -NoTypeInformation
# show on screen
Write-Verbose "Created '$outputFile'"
}
}
}
It creates a folder in the current script path called 'InstalledSoftware' where the csv file per computer is saved as 'msinfo32COMPUTERNAME.csv'
Call it like this for the local computer:
Get-InstalledSoftware -NamePattern * -ExcludeUpdates -Verbose
or feed it an array of computer names (you have admin permissions on) like this:
Get-InstalledSoftware -ComputerName machine1,machine2,machine3 -NamePattern * -ExcludeUpdates -Verbose
edited Nov 21 '18 at 16:07
answered Nov 21 '18 at 14:56
TheoTheo
4,7062520
4,7062520
@Perfect.exe If you find my answer has helped you, then feel free to accepting the answer
– Theo
Dec 1 '18 at 10:58
add a comment |
@Perfect.exe If you find my answer has helped you, then feel free to accepting the answer
– Theo
Dec 1 '18 at 10:58
@Perfect.exe If you find my answer has helped you, then feel free to accepting the answer
– Theo
Dec 1 '18 at 10:58
@Perfect.exe If you find my answer has helped you, then feel free to accepting the answer
– Theo
Dec 1 '18 at 10:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413013%2ftrying-to-develop-auditing-program%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you're using PSv5+, can you not just use something like
Get-Package | Sort Name | Export-Csv C:tempinstalledItems.csv -NoTypeInformation
?– trebleCode
Nov 21 '18 at 14:01
As for the
Size
issue:objReg.GetDWORDValue
gets a numeric value. You are comparing it to a string withIf Size <> "" Then
. Change that toIf Size <> 0 Then
.– Theo
Nov 21 '18 at 15:00