The second part needs to run as the user, not as System. I think
Win32_Printer is only populated with printers of the user. So if it runs as
system, you'll only get printers the System account can see.

On Wed, Jun 8, 2016 at 1:50 PM Todd Hemsell <[email protected]> wrote:

> run it as a DCM rule as user with admin permissions.
>
> On Wed, Jun 8, 2016 at 1:30 PM, Murray, Mike <[email protected]> wrote:
>
>> I’m still trying to inventory network printers on computers. The script
>> below is a combination of the two scripts mentioned here:
>> https://gallery.technet.microsoft.com/SCCM-2012-NETWORK-PRINTER-776b59b4
>>
>>
>>
>> I deploy it as a package that runs only when a user is logged on. It
>> runs, but only does the first part of the script. It creates a new registry
>> entry under HKLM\SOFTWARE\Wow6432Node called SCCMINVENTORY, and another
>> under that called NETWORKPRINTERS. But the printers do not enumerate. If I
>> run the script locally, they do. Any ideas why?
>>
>>
>>
>> #Configure Registry
>>
>> 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}
>>
>>
>>
>> #Enumerate Printers
>>
>> $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
>>
>>     }
>>
>> }
>>
>>
>>
>>
>>
>>
>>
>> Best Regards,
>>
>>
>>
>> Mike Murray
>>
>> Desktop Management Coordinator - IT Support Services
>>
>> California State University, Chico
>>
>> 530.898.4357
>> [email protected]
>>
>>
>>
>> Remember, Chico State will NEVER ask you for your password via email!
>>
>> For more information about recognizing phishing scam emails go to:
>> http://www.csuchico.edu/isec/basics/spam-and-phishing.shtml
>>
>>
>>
>>
>>
>>
>
>



Reply via email to