国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PowerShell > 正文

PowerShell查詢和刪除打印任務操作代碼實例

2020-03-26 19:10:41
字體:
來源:轉載
供稿:網友

適用于Windows 8.1或Server 2012 R2

Windows 8.1 和 Server 2012 R2上自帶了一個PowerShell組件:“PrintManagement“,它包含了所有管理本機和遠程打印機的命令。

在之前的小技巧中,我們演示了如何讀取打印機任務。每一個打印任務都有一個屬性JobStatus ,用來表示該任務是否打印成功。

所有的狀態可以這樣獲取:

 

復制代碼 代碼如下:

PS> Import-Module PrintManagement
 
PS> [Microsoft.PowerShell.Cmdletization.GeneratedTypes.PrintJob.JobStatus]::GetNames([Microsoft.PowerShell.Cmdletization.GeneratedTypes.PrintJob.JobStatus])
Normal
Paused
Error
Deleting
Spooling
Printing
Offline
PaperOut
Printed
Deleted
Blocked
UserIntervention
Restarted
Complete
Retained
RenderingLocally

 

接下來就可以過濾已存在的任務了。比如你想列出打印任務是否已經完成,或者遇到了故障:

復制代碼 代碼如下:

$ComputerName = $env:COMPUTERNAME
 
Get-Printer -ComputerName $ComputerName |  ForEach-Object {
  Get-PrintJob -PrinterName $_.Name -ComputerName $ComputerName |
    Where-Object { $_.JobStatus -eq 'Complete' -or $_.JobStatus -eq 'Error' -or $_.JobStatus -eq 'Printed'}
 }

 

刪除打印任務也非常簡單,Remove-PrintJob即可:

 

復制代碼 代碼如下:

$ComputerName = $env:COMPUTERNAME
 
Get-Printer -ComputerName $ComputerName |  ForEach-Object {
  Get-PrintJob -PrinterName $_.Name -ComputerName $ComputerName |
    Where-Object { $_.JobStatus -eq 'Complete' -or $_.JobStatus -eq 'Error' -or $_.JobStatus -eq 'Printed'}
 } |
 Remove-PrintJob -CimSession $ComputerName

 

 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北海市| 潞城市| 平和县| 琼中| 崇文区| 巴南区| 闸北区| 兰坪| 清苑县| 库尔勒市| 漯河市| 民权县| 兴宁市| 唐山市| 长武县| 海丰县| 定襄县| 雅安市| 洮南市| 城步| 云安县| 沈阳市| 镇巴县| 丰宁| 当涂县| 溧水县| 扎兰屯市| 三河市| 恩施市| 旬邑县| 报价| 庆云县| 静宁县| 邯郸县| 寿宁县| 饶平县| 江都市| 贡嘎县| 抚顺县| 孟津县| 醴陵市|