Network shares and printers

Post Reply
MBone
Posts: 5
Joined: 26. Jun 2023, 17:59
Contact:

Network shares and printers

Post by MBone » 15. Sep 2023, 20:02

Hello,
Is there an efficient way to gather mapped network shares and installed network printers from all profiles on a computer using M42 Empirum? In an older system, we used a couple of PS scripts to accomplish this and the output was stored on each computer record under a Powershell section. I have attempted to use custom WMI queries to accomplish this but they seem to only be reading data from the account that is executing the Inventory app, rather than any (or all) User profiles on the system. I was going to attempt to use a Registry scan but this data is stored in HCU and I am not sure how the system handles wildcards in a Registry value.

WMI Query for Network Shares:
SELECT Name, ProviderName FROM Win32_MappedLogicalDisk

WMI Query for installed Printers:
SELECT Name FROM Win32_Printer

While testing these, I get no values back from the Network Share query and the Printer query only returns local printers that all profiles on our systems have.

Can we use a wildcard in a Registry Scan to drill into HCU,S-1-5-21-##########-#########-##########-*\Network and return each of the keys therein as well as the RemotePath value of each key?

For example, for HKEY_USERS\S-1-5-21-1234567890-123456789-1234567890-12345\Network there are 5 keys nested therein;
Q: RemotePath - \\fileserver1\share1
W: RemotePath - \\fileserver1\share2
E: RemotePath - \\fileserver1\share3
R: RemotePath - \\fileserver2\share1
T: RemotePath - \\fileserver2\share2

Could I capture all of the drive letter keys and the value of the RemotePath REG_SZ String?


For printers, can the same logic be applied but instead, capturing the names of the Keys under \Printers\Connections as well as the Server REG_SZ value nested therein, for each user?

For example, for HKEY_USERS\S-1-5-21-1234567890-123456789-1234567890-12345\Printers\Connections has two keys;
,,printserver1,PrinterName1 | Server: \\printserver1
,,printserver2,PrinterName1 | Server: \\printserver2


Any help with this would be greatly appreciated! 8)

User avatar
ctearney
Posts: 229
Joined: 21. Feb 2014, 04:14
Location: Dallas, Texas
Contact:

Re: Network shares and printers

Post by ctearney » 02. Oct 2023, 20:15

A couple of years back Matrix42 assisted me with putting together an two part inventory that would run under the users context, save a file locally which would then be used to provided the needed data. For our need it was for user level installed applications. This worked well but it is a few moving parts with a system execute, user execute, and then another system execute to upload the inventory. It also created additional software entries into the inventory for the app for the user level installs.

MBone
Posts: 5
Joined: 26. Jun 2023, 17:59
Contact:

Re: Network shares and printers

Post by MBone » 03. Oct 2023, 16:57

ctearney wrote: 02. Oct 2023, 20:15 A couple of years back Matrix42 assisted me with putting together an two part inventory that would run under the users context, save a file locally which would then be used to provided the needed data. For our need it was for user level installed applications. This worked well but it is a few moving parts with a system execute, user execute, and then another system execute to upload the inventory. It also created additional software entries into the inventory for the app for the user level installs.
Do you have any documentation or a link to the forum post (if the communication happened there) I could use as a reference? I understand what you said at a context level but I'm not really sure how to get it going at the implementation level....

Configure per-user install that runs script(s) that output to a file I get.
How does the data in the file then get read by Inventory and append each user's data into the computer Inventory record?

MBone
Posts: 5
Joined: 26. Jun 2023, 17:59
Contact:

Re: Network shares and printers

Post by MBone » 05. Oct 2023, 21:02

Wanted to post an update in case anyone was following along...

I've built a power shell script that ultimately creates new reg_sz values under a new key in HKLM using a foreach loop that builds off of Get-ItemProperty scanning the network keys and values for each profile on the computer using HKEY_User.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Find all drives listed contained in each user's Network folder
$Drives = Get-ItemProperty "Registry::HKEY_USERS\*\Network\*"
# Store registry path for new Key
$RegPath = "Registry::HKEY_Local_Machine\Software\Matrix42\MappedDrives"

if (Test-Path -Path "Registry::$RegPath") {
}
Else {
New-Item -Path "Registry::HKEY_LOCAL_MACHINE\Software\Matrix42\MappedDrives"
}

# Create registry keys for each drive found
ForEach ( $Drive in $Drives ) {

# PSParentPath looks like this: Microsoft.PowerShell.Core\Registry::HKEY_USERS\S-1-5-21-##########-##########-##########-####\Network
$SID = ($Drive.PSParentPath -split '\\')[2]

# Use .NET to look up the username from the SID
$Username = ([System.Security.Principal.SecurityIdentifier]"$SID").Translate([System.Security.Principal.NTAccount])
$DriveLetter = $Drive.PSChildName
$RemotePath = $Drive.RemotePath
$Delimiter = "-"
$KeyName = "$Username + $DriveLetter"

Set-ItemProperty -Path $RegPath -Name $KeyName -Value $RemotePath

}

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The values are created with a Name in the format of "domain\username + driveletter" and the Data lists the UNC path used to map the drives.


This is all well and good but I am unable to successfully get the Inventory scanner to pull these in with a Registry Scan or User Defined Values customization. Has anyone had success using any wildcards in either of these to scan and import any values (Names and data) that might exist under a key?

In this case it would be best to grab any and all String Values that are nested in the MappedDrives key.

Post Reply

Return to “Inventory”

Who is online

Users browsing this forum: No registered users and 0 guests