Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function Get-OffilnePrinter
{
[CmdletBinding()]
[OutputType([int])]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string[]]$ComputerName
)
Begin
{
Write-Verbose -Message "[BEGIN] Function Starting"
}
Process
{
foreach ($computer in $ComputerName)
{
if (Test-Connection -ComputerName $computer -Count 2 -Quiet)
{
Write-Verbose -Message "[PROCESS] $computer is online , querying it"
#Take a look at the MSDN documentation why the below filters are used
Get-WmiObject -query "Select * From Win32_Printer WHERE (PrinterStatus='7') OR (ExtendedPrinterStatus='9')" -ComputerName $computer
}
}
}
End
{
Write-Verbose -Message "[END] Function Ending"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment