How to collect printer information from W10 with Intune

This is an easy way to collect the installed printer list from a Windows 10 machine using Intune and PowerShell.

If you need to get a list of all the printers installed on a user's computer and you are managing it with Intune, this is one way

There will be a local log created - it is used by Intune to verify the script has been applied

Also, the files generated will contain the computer name for easy tracking


1. Get yourself an FTP server, available on the outside - if possible just basic access

-  change the below attributes to your custom ones

ftp.company.com

username

password

2. Change the below script to match your FTP server details

*****************************************************************************

 # Create a log of all results every time this script runs

Start-Transcript -Path "C:\ScopeIntuneLogs\Printers.log"

 # Start script

$startDate = Get-Date

"Script started at $startDate..."

Write-Host ""

# Define variables

$FTPUsername = "username"

$FTPPassword = "password"

$CSVFileName = "Printers_" + $env:UserName + ".csv"

$CSVFilePath = $env:TEMP

$CSVFile = $CSVFilePath + "\" + $CSVFileName

$CSVRemoteFile = "ftp://ftp.company.com/" + $CSVFileName

# Get Printer information and export to CSV

Write-Host "Collecting information about all installed printers and export a CSV file to: $CSVFile..."

Get-WMIObject -Class Win32_Printer | Export-csv $CSVFile

Write-Host "...done."

Write-Host ""

# Create FTP Request Object

Write-Host "Connecting to FTP server..."

$FTPRequest = [System.Net.FtpWebRequest]::Create("$CSVRemoteFile")

$FTPRequest = [System.Net.FtpWebRequest]$FTPRequest

$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile

$FTPRequest.Credentials = new-object System.Net.NetworkCredential($FTPUsername, $FTPPassword)

$FTPRequest.UseBinary = $true

$FTPRequest.UsePassive = $true

Write-Host "...done."

# Read the File for Upload

Write-Host "Reading File to upload..."

$FileContent = gc -en byte $CSVFile

$FTPRequest.ContentLength = $FileContent.Length

Write-Host "...done."

# Get Stream Request by bytes

Write-Host "Uploading file to the FTP server..."

$Run = $FTPRequest.GetRequestStream()

$Run.Write($FileContent, 0, $FileContent.Length)

Write-Host "...done."

# Cleanup

$Run.Close()

$Run.Dispose()

# End script

$endDate = Get-Date

$runTime = NEW-TIMESPAN –Start $StartDate –End $EndDate

"Script finished at $endDate - Runtime: $($runTime.totalseconds) seconds."  

 Stop-Transcript

*****************************************************************************

2. Package the script as an Intuneview file - see here

3. Go to Intune / Apps / Windows / add an app

4. Add the Windows App (Win32) type

5. Use the Install command as follows: 

powershell -Ex Bypass -windowstyle Hidden -file "script_name.ps1"

There is no need for an uninstall command, just add a dot there

6. On the detection rules, add the path to the log file

C:\ScopeIntuneLogs

Check if the log file (Printers.log) exists, or you can use check by file date so you can re-run it later on.

7. Assign it to all users

8. Collect the data from the FTP 


By the way, if you want to stop users from installing local printers, an article will follow

Comments

  1. Amazingly helpful which you have shared here. I am impressed by the details and also it is a significant article for us. Continue imparting this sort of info, Thank you.Printer Ink Toner Cartridge For Sale

    ReplyDelete

Post a Comment