Hi all,
Put in a support ticket for this as well, not sure if AM support helps with custom worklets or not, anyways… here’s the issue i’m trying to solve. We’re migrating our printers to Universal Print in Azure as we’re slowly removing on-prem servers. So, I need to remove printers from users' computers that were previously hosted via a print server. So, I had Otto help me out, because I don’t know Powershell scripting for crap, and this is what the results were -
Here's the Evaluation Code -
# ======================
# Otto AI Generated Code
# ======================
# Define the printer names to check
$printerNames = @(
'\\fpwc03\CO-HR1', # First printer to check
'\\fpwc03\CO-Main PS' # Second printer to check
)
# Initialize a flag to determine if any printer is installed
$printerFound = $false
# Loop through each printer name to check existence
foreach ($printerName in $printerNames) {
if (Get-Printer -Name $printerName -ErrorAction SilentlyContinue) {
# If the printer exists, set the flag to true
$printerFound = $true
Write-Host "Printer '$printerName' is installed."
} else {
Write-Host "Printer '$printerName' is not installed."
}
}
# Check if at least one printer was found
if ($printerFound) {
# Return non-compliance message
Write-Host "Non-compliance detected: At least one specified printer is installed."
exit 1 # Exit with a non-zero status to indicate non-compliance
} else {
Write-Host "Compliance check passed: No specified printers are installed."
exit 0 # Exit with a zero status to indicate compliance
}
When run on my machine manually (with the '\\fpwc03\CO-Main PS' printer installed but not the other one), it detects the printer and returns with the "Non-compliance detected: At least one specified printer is installed." as it should, and then runs the remediation code.
However the remediation code isn't working, at least from Automox to my machine. Here's the remediation code -
# ======================
# Otto AI Generated Code
# ======================
# Define the printer names to check
$printerNames = @(
'\\fpwc03\CO-HR1', # First printer to check
'\\fpwc03\CO-Main PS' # Second printer to check
)
# Initialize a flag to determine if any printer is installed
$printerFound = $false
# Loop through each printer name to check existence
foreach ($printerName in $printerNames) {
if (Get-Printer -Name $printerName -ErrorAction SilentlyContinue) {
# If the printer exists, set the flag to true
$printerFound = $true
Write-Host "Printer '$printerName' is installed."
# Remove the printer
Remove-Printer -Name $printerName
Write-Host "Printer '$printerName' has been uninstalled successfully."
} else {
Write-Host "Printer '$printerName' is not installed."
}
}
# Check if at least one printer was found and removed
if ($printerFound) {
Write-Host "At least one specified printer was found and removed."
} else {
Write-Host "No specified printers are installed. No action taken."
}
Here's the results when it's run with Automox (which if this was true… it not detecting the printer is installed, it should never even get to the remediation code correct?) -
Printer '\\fpwc03\CO-HR1' is not installed.
Printer '\\fpwc03\CO-Main PS' is not installed.
No specified printers are installed. No action taken.
However when I manually run the remediation code on my computer, it works just fine -
Printer '\\fpwc03\CO-HR1' is not installed.
Printer '\\fpwc03\CO-Main PS' is installed.
Printer '\\fpwc03\CO-Main PS' has been uninstalled successfully.
At least one specified printer was found and removed.
Any help you could provide to get this working would be great!! Thx!!