プリンター ポートを WMI オブジェクトとして削除する際に問題が発生する
これ
param(
[Parameter(Mandatory=$true)]
[string] $printerName
)
$printer=gwmi win32_Printer -filter "name='$printerName'"
$printer.Delete()
Write-Host $printer.portname
$port=gwmi win32_tcpipprinterport -filter "name='$($printer.portname)'" -EnableAllPrivileges
Write-host $port
$port.Delete()
次の場合に失敗します。
Exception calling "Delete" with "0" argument(s): "Generic failure "
At line:14 char:1
+ $port.Delete()
+ ~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
ただし、間に 10 秒間スリープを追加する$printer.Delete
と$port=gwmi...
、機能します。
それが何であるか、そして睡眠以外でそれを修正する方法について何か提案はありますか?