![](/img/trans.png)
[英]Powershell: Exception calling “GetOwner” : “Not found ” when invoked as job
[英]Exception calling "GetOwner"
團隊! 最近,我的遠程 pssession 腳本在獲取進程所有者時失敗。
#Some code up and down the fragmet
#Use WMI or CIM cmdlets.
$UseCIM = !( Test-GetWMIObjectPresent ) #local function to choose CIM or WMI methods
if ( $UseCIM ) {
$ProcessArray = Get-CimInstance -ClassName 'Win32_Process' -Property $ProcessProperties
}
Else {
$ProcessArray = Get-WmiObject -Class 'Win32_Process' -Property $ProcessProperties
}
$ProcessArray | Add-Member -NotePropertyName 'User' -NotePropertyValue ''
$ProcessProperties += 'User'
$ProcessArray | Add-Member -NotePropertyName 'ComputerName' -NotePropertyValue $env:COMPUTERNAME
$ProcessProperties += 'ComputerName'
foreach ( $Item in $ProcessArray ){
try {
if ( $UseCIM ) {
# We have error here!!!
$Owner = $Item | Invoke-CimMethod -MethodName 'GetOwner' -ErrorAction 'SilentlyContinue'
}
Else {
# and here!
$Owner = $Item | Invoke-WmiMethod -Name 'GetOwner' -ErrorAction 'SilentlyContinue'
}
if ( $Owner ){
if ( $Owner.domain ){
$Item.User = "$( $Owner.domain )\$( $Owner.User )"
}
Else {
$Item.User = "$( $Owner.User )"
}
}
}
Catch{
Add-ToLog -Message "$_" -Display -Status "error"
}
}
遠程用戶具有管理權限。
我們有錯誤:
調用“GetOwner”的異常:“由於對象的當前狀態,操作無效。”
如果我們在本地會話下運行它,則不會發生錯誤。 有什么建議么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.