Network Printer inventory Using SCCM [Microsoft endpoint configuration manager]
SCCM HW inventory agent runs as the ‘SYSTEM’ and cannot see the end-users network drives and printers. The following two step process will help circumvent…
SCCM HW inventory agent runs as the ‘SYSTEM’ and cannot see the end-users network drives and printers. The following two step process will help circumvent…
SCCM HW inventory agent runs as the ‘SYSTEM’ and cannot see the end-users network drives and printers. The following two step process will help circumvent the above stated limitation. |
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\NETWORKPRINTERS)) {new-item HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS -ErrorAction SilentlyContinue}
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\PowerShell.exe -NonInteractive -WindowStyle Hidden -noprofile -ExecutionPolicy Bypass -file .\PrinterInvRegSetup.ps12) CAPTURE CURRENT USER’S PRINTERS AND WRITE THOSE ENTRIES TO THE ABOVE CREATED REGISTRY KEYS.
$printers = Get-WMIObject -class Win32_Printer -ErrorAction SilentlyContinue|select-Object -Property ServerName,ShareName,Location,DriverName,PrintProcessor,PortName,Local |Where-Object {$_.Local -ne $true}-ErrorAction SilentlyContinue ForEach($printer in $printers){ $PServerName= $printer.ServerName -replace ('\\','') $PShareName = $printer.ShareName $PLocation = $printer.Location $PDriverName = $printer.DriverName $PPrintProcessor = $printer.PrintProcessor $PPortName = $printer.PortName if ((Test-Path HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS)) { if ((Test-Path "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS\$PShareName on $PServerName")) { Remove-item "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS\$PShareName on $PServerName" -Force -ErrorAction SilentlyContinue } New-item "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS\$PShareName on $PServerName" -ErrorAction SilentlyContinue New-ItemProperty "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS\$PShareName on $PServerName" -Name "PrintServer" -Value $PServerName -PropertyType "String" -ErrorAction SilentlyContinue New-ItemProperty "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS\$PShareName on $PServerName" -Name "PrinterQueue" -Value $PShareName -PropertyType "String" -ErrorAction SilentlyContinue New-ItemProperty "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS\$PShareName on $PServerName" -Name "PrinterLocation" -Value $PLocation -PropertyType "String" -ErrorAction SilentlyContinue New-ItemProperty "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS\$PShareName on $PServerName" -Name "PrinterDriver" -Value $PDriverName -PropertyType "String" -ErrorAction SilentlyContinue New-ItemProperty "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS\$PShareName on $PServerName" -Name "PrintProcessor" -Value $PPrintProcessor -PropertyType "String" -ErrorAction SilentlyContinue New-ItemProperty "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS\$PShareName on $PServerName" -Name "PrinterPortName" -Value $PPortName -PropertyType "String" -ErrorAction SilentlyContinue New-ItemProperty "HKLM:\SOFTWARE\SCCMINVENTORY\NETWORKPRINTERS\$PShareName on $PServerName" -Name "DateInventoried" -Value $(get-date) -PropertyType "String" -ErrorAction SilentlyContinue } }
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\PowerShell.exe -NonInteractive -WindowStyle Hidden -noprofile -ExecutionPolicy Bypass -file .\NetworkPrinterInventory.ps13) CREATE A DEPLOYMENT AND SET IT TO ‘RUN ALWAYS’ AND MAKE IT A REQUIREMENT.
//======================== // Added extensions Start //======================== #pragma namespace ("\\\\.\\root\\cimv2") #pragma deleteclass("NETWORKPRINTERS", NOFAIL) [dynamic, provider("RegProv"), ClassContext("Local|HKEY_LOCAL_MACHINE\\SOFTWARE\\SCCMINVENTORY\\NETWORKPRINTERS")] Class NETWORKPRINTERS { [key] string KeyName; [PropertyContext("PrintServer")] String PrintServer; [PropertyContext("PrinterQueue")] String PrinterQueue; [PropertyContext("PrinterLocation")] String PrinterLocation; [PropertyContext("PrinterDriver")] String PrinterDriver; [PropertyContext("PrintProcessor")] String PrintProcessor; [PropertyContext("PrinterPortName")] String PrinterPortName; [PropertyContext("DateInventoried")] String DateInventoried; }; //======================== // Added extensions end //========================5) SAVE THE BELOW DATA INTO A FILE CALLED ‘AWESOME.MOF’.
#pragma namespace (“\\\\.\\root\\cimv2\\SMS”) #pragma deleteclass(“NETWORKPRINTERS”, NOFAIL) [SMS_Report(TRUE),SMS_Group_Name("NETWORKPRINTERS"),SMS_Class_ID("NETWORKPRINTERS")] Class NETWORKPRINTERS: SMS_Class_Template { [SMS_Report(TRUE),key] string KeyName; [SMS_Report(TRUE)] String PrintServer; [SMS_Report(TRUE)] String PrinterQueue; [SMS_Report(TRUE)] String PrinterLocation; [SMS_Report(TRUE)] String PrinterDriver; [SMS_Report(TRUE)] String PrintProcessor; [SMS_Report(TRUE)] String PrinterPortName; [SMS_Report(TRUE)] String DateInventoried; };6) IMPORT ‘AWESOME.MOF’ INTO SCCM DEFAULT CLIENT SETTINGS.