SCCM Network drives inventory. List all user network mapped drives
SCCM HW inventory agent runs as the ‘SYSTEM’ and cannot see the end-users network drives and printers. This post explains the process of creating an SCCM network drive report.
The following two-step process will help circumvent the above-stated limitation. |
1) CREATE HKEY_LOCAL_MACHINE\SOFTWARE\SCCMINVENTORY\NETWORKDRIVES PATH IN THE REGISTRY.
- Create an SCCM package.
- The package should run as an administrator.
- The package should run whether or not a user is logged on.
keywords in this post: network drive inventory, List all user network drives, SCCM Mapped drives
POWERSHELL PACKAGE 1 (Prerequisite):
if (!(Test-Path HKLM:\SOFTWARE\SCCMINVENTORY)) {new-item HKLM:\SOFTWARE\SCCMINVENTORY -ErrorAction SilentlyContinue} $perm = get-acl HKLM:\SOFTWARE\SCCMINVENTORY -ErrorAction SilentlyContinue $rule = New-Object System.Security.AccessControl.RegistryAccessRule("Authenticated Users","FullControl", "ContainerInherit, ObjectInherit", "InheritOnly", "Allow") -ErrorAction SilentlyContinue $perm.SetAccessRule($rule) Set-Acl -Path HKLM:\SOFTWARE\SCCMINVENTORY $perm -ErrorAction SilentlyContinue if (!(Test-Path HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKDRIVES)) {new-item HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKDRIVES -ErrorAction SilentlyContinue}
- SAVE POWERSHELL FILE AS: NetworkDriveInvRegSetup.ps1
- SETUP THE SCCM PACKAGE/PROGRAM WITH COMMAND LINE:
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\PowerShell.exe -NonInteractive -WindowStyle Hidden -noprofile -ExecutionPolicy Bypass -file .\NetworkDriveInvRegSetup.ps1
2) CAPTURE CURRENT USER’S NETWORK DRIVES AND WRITE THOSE ENTRIES TO THE ABOVE CREATED REGISTRY KEYS.
- Create an SCCM package
- The package should be run only when a user is logged in.
POWERSHELL PACKAGE 2 (Main):
$nDrives = Get-WmiObject Win32_MappedLogicalDisk | select ProviderName,size,freeSpace, @{Name="driveLetter";Expression={$_.Name}}, @{Name="path";Expression={$_.ProviderName}}, @{Name="serverName";Expression={$($_.ProviderName).Split("\")[2]}}, @{Name="shareName";Expression={$($_.ProviderName.TrimEnd("\")).Split("\")[-1]}} ForEach($nDrive in $nDrives){ $nServerName= $nDrive.serverName $nShareName = $nDrive.shareName $nDriveLetter = $nDrive.driveLetter if ((Test-Path HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKDRIVES)) { if ((Test-Path "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKDRIVES\$nShareName on $nServerName")) { Remove-item "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKDRIVES\$nShareName on $nServerName" -Force -ErrorAction SilentlyContinue } New-item "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKDRIVES\$nShareName on $nServerName" -ErrorAction SilentlyContinue New-ItemProperty "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKDRIVES\$nShareName on $nServerName" -Name "servername" -Value $nServerName -PropertyType "String" -ErrorAction SilentlyContinue New-ItemProperty "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKDRIVES\$nShareName on $nServerName" -Name "sharename" -Value $nShareName -PropertyType "String" -ErrorAction SilentlyContinue New-ItemProperty "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKDRIVES\$nShareName on $nServerName" -Name "driveletter" -Value $nDriveLetter -PropertyType "String" -ErrorAction SilentlyContinue New-ItemProperty "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKDRIVES\$nShareName on $nServerName" -Name "dateinventoried" -Value $(get-date -Format "dd/MM/yyyy") -PropertyType "String" -ErrorAction SilentlyContinue } }
- SAVE POWERSHELL FILE AS NetworkDriveInventory.ps1
- SETUP THE SCCM PACKAGE/PROGRAM WITH COMMAND LINE:
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\PowerShell.exe -NonInteractive -WindowStyle Hidden -noprofile -ExecutionPolicy Bypass -file .\NetworkDriveInventory.ps1
3) CREATE A DEPLOYMENT AND SET IT TO ‘RUN ALWAYS’ AND MAKE IT A REQUIREMENT.
- Now deploy the second package and set the first package as a prerequisite (Check the box – Always run the prerequisite package)
- The deployment should be set to run every 4 hours and ‘Always rerun’. Mark the deployment as required.
4) ADD THE FOLLOWING IN BETWEEN THE EXTENSION SECTION WITHIN YOUR CONFIGURATION.MOF.
Click here to learn how to edit the configuration.mof file.
//======================== // Added extensions Start //======================== #pragma namespace ("\\\\.\\root\\cimv2") #pragma deleteclass("NETWORKDRIVES", NOFAIL) [dynamic, provider("RegProv"), ClassContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\SCCMINVENTORY\\NETWORKDRIVES")] Class NETWORKDRIVES { [key] string KeyName; [PropertyContext("servername")] String servername; [PropertyContext("sharename")] String sharename; [PropertyContext("driveletter")] String driveletter; [PropertyContext("dateinventoried")] String dateinventoried; }; //======================== // Added extensions end //========================
5) SAVE THE BELOW DATA INTO A FILE CALLED ‘AWESOME.MOF’. (Optional)
#pragma namespace (“\\\\.\\root\\cimv2\\SMS”) #pragma deleteclass(“NETWORKDRIVES”, NOFAIL) [SMS_Report(TRUE),SMS_Group_Name("NETWORKDRIVES"),SMS_Class_ID("NETWORKDRIVES")] Class NETWORKDRIVES: SMS_Class_Template { [SMS_Report(TRUE),key] string KeyName; [SMS_Report(TRUE)] String servername; [SMS_Report(TRUE)] String sharename; [SMS_Report(TRUE)] String driveletter; [SMS_Report(TRUE)] String dateinventoried; };
6) IMPORT ‘AWESOME.MOF’ INTO SCCM DEFAULT CLIENT SETTINGS.
- Either import the above MOF file into the Client Setting/Default Client Settings/Hardware Inventory/Classes/Import. Select the option to import everything.
- Alternatively, if you have compiled the MOF manually on the PC, Add a new reporting class by clicking the ‘Add’ button and connecting to the PC and selecting the WMI class ‘NETWORKDRIVES‘
and that is it. The SCCM resource explorer should soon see the Network drives. - You can then use the ‘NETWORKDRIVES‘ class to generate reports or create Queries.
keywords in this post: network drive inventory, List all user network drives, SCCM Mapped drives
Click here to learn more about network printer inventory.
Have you created a SQL report using the inventory data?
I think step 5 has a cut-and-paste error, it is the Configuration MOF data again… Thank you!
@deaniii Thanks for letting us know. I’ve made the necessary changes to the article.
+ Please note that step 5 is optional. If you have manually complied the MOF on a machine; you can add a new reporting class by clicking the ‘Add’ button (In Client settings / HW inventory classes) and connecting to the machine and selecting the WMI class ‘NETWORKDRIVES‘