cancel
Showing results for 
Search instead for 
Did you mean: 

Using PowerShell to Install a Printer ... using ChatGPT

JCDavid
Iron II
Iron II

Last night I asked ChatGPT to write me a PowerShell Script to install a printer from an installer in my Dropbox tenant. This was what it gave me:

 

# Define the URL of the print driver file in Dropbox
$driverURL = "https://www.dropbox.com/s/example/exampledriver.inf?dl=1"

# Define the path where the driver should be downloaded and installed
$driverPath = "C:\PrinterDrivers"

# Create the driver directory if it does not already exist
if (!(Test-Path $driverPath)) {
    New-Item -ItemType Directory -Path $driverPath
}

# Download the driver from Dropbox
Invoke-WebRequest -Uri $driverURL -OutFile "$driverPath\exampledriver.inf"

# Install the driver
$installResult = pnputil.exe /add-driver "$driverPath\exampledriver.inf" /install

# Check if the installation was successful
if ($installResult -eq "The driver package was successfully installed.") {
    Write-Host "Driver installed successfully."
} else {
    Write-Host "Driver installation failed: $installResult"
}

 

The output from the JumpCloud commands console was "0", meaning, it worked. I'll verify that in Windows shortly. 

 

Screenshot 2023-02-23 at 4.21.53 PM.png

3 REPLIES 3

Kathlyn
Novitiate II

What are some common troubleshooting steps if the PowerShell script fails to install the printer correctly?

Kathlyn,

I wrote this one as an experiment when generative AI was new. Rather than troubleshoot: JumpCloud's app repository can deploy MSI packages and some drivers are available in the Microsoft Store. The repo can also deploy MSFT Store apps (at least in EA) at this time. Those options may be easier.

But now that I think of it... we have a privilege elevation feature in early access that would be even easier. 

Least privilege is an important security practice, but there are situations when a user may require admin rights (it’s almost always printers). We’re introducing privilege management that’s as-needed, and fully audited, to grant elevated permissions on a fully managed basis.

Directory Insights will help you track events with a full audit trail for your compliance lifecycle. Privilege management will simplify support while ensuring strong entitlement management

You Might Like

New to the site? Take a look at these additional resources:

Community created scripts

Keep up with Product News

Read our community guidelines

Ready to join us? You can register here.