Get local Admins on Remote Server, running as Job












0















I have a working script that gets local Admins on remote servers, but sometimes there's an issue with one of the servers in the list (even though Test-Connection succeeds) that will hang and stops the script from continuing. So I've been looking into using jobs as a means of having a timeout feature if a server takes too long to respond.



In my test script, I'm getting a list of System.__ComObject objects back, which seems promising, but I can't parse them like usual and get error:




Exception calling "InvokeMember" with "5" argument(s): "Method
'System.Management.Automation.PSCustomObject.ADSPath' not found."
At c:timeout.ps1:48 char:3
+ $member.GetType().Invokemember("ADSPath","GetProperty",$null, ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : MissingMethodException


NOTE: For above error, it's repeated for Name, Class and ADSPath (bascially all the invokes I tried.



Here is the script code:



# Test Timeout functionality
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string]$Computer
)

$timeout = 90 ## seconds
$retryInterval = 5 ## seconds
$LocalGroupName = "Administrators"
$group = $null
$members = $null

Write-Host "Working on $($computer)..."

Write-Verbose "Start Job..."
$job1 = {
Param($computer,$localgroupname)

$group =[ADSI]"WinNT://$computer/$LocalGroupName"
@($group.psbase.Invoke("Members"))
}
Start-Job -Name "Members" $job1 -ArgumentList $computer,$localgroupname

$Check_Job = Get-Job -Name "Members"
$timer = [Diagnostics.Stopwatch]::StartNew()

while ($timer.Elapsed.TotalSeconds -lt $Timeout) {
if ($Check_Job.State -eq 'Completed') {
$members = Receive-Job -Name "Members"
break
}

Start-Sleep -Seconds $RetryInterval
Write-Verbose -Message "Waiting [$totalSecs]sec until retry..."
}
$timer.Stop()

if (!$members) {
Write-Host "No members found in the group"
} else {
foreach($member in $members) {
Write-Host "-------------------------------------"
$member.GetType().InvokeMember("Name","GetProperty",$null,$member,$null)
$member.GetType().InvokeMember("Class","GetProperty",$null,$member,$null)
$member.GetType().InvokeMember("ADSPath","GetProperty",$null,$member,$null)
}
}


What am I doing wrong?










share|improve this question

























  • while i have never tried it, i thot that the objects returned by a job where NOT live objects. if that is correct, then your .InvokeMember() call is likely returning garbage since there likely aint anything there to invoke.

    – Lee_Dailey
    Nov 26 '18 at 22:30
















0















I have a working script that gets local Admins on remote servers, but sometimes there's an issue with one of the servers in the list (even though Test-Connection succeeds) that will hang and stops the script from continuing. So I've been looking into using jobs as a means of having a timeout feature if a server takes too long to respond.



In my test script, I'm getting a list of System.__ComObject objects back, which seems promising, but I can't parse them like usual and get error:




Exception calling "InvokeMember" with "5" argument(s): "Method
'System.Management.Automation.PSCustomObject.ADSPath' not found."
At c:timeout.ps1:48 char:3
+ $member.GetType().Invokemember("ADSPath","GetProperty",$null, ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : MissingMethodException


NOTE: For above error, it's repeated for Name, Class and ADSPath (bascially all the invokes I tried.



Here is the script code:



# Test Timeout functionality
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string]$Computer
)

$timeout = 90 ## seconds
$retryInterval = 5 ## seconds
$LocalGroupName = "Administrators"
$group = $null
$members = $null

Write-Host "Working on $($computer)..."

Write-Verbose "Start Job..."
$job1 = {
Param($computer,$localgroupname)

$group =[ADSI]"WinNT://$computer/$LocalGroupName"
@($group.psbase.Invoke("Members"))
}
Start-Job -Name "Members" $job1 -ArgumentList $computer,$localgroupname

$Check_Job = Get-Job -Name "Members"
$timer = [Diagnostics.Stopwatch]::StartNew()

while ($timer.Elapsed.TotalSeconds -lt $Timeout) {
if ($Check_Job.State -eq 'Completed') {
$members = Receive-Job -Name "Members"
break
}

Start-Sleep -Seconds $RetryInterval
Write-Verbose -Message "Waiting [$totalSecs]sec until retry..."
}
$timer.Stop()

if (!$members) {
Write-Host "No members found in the group"
} else {
foreach($member in $members) {
Write-Host "-------------------------------------"
$member.GetType().InvokeMember("Name","GetProperty",$null,$member,$null)
$member.GetType().InvokeMember("Class","GetProperty",$null,$member,$null)
$member.GetType().InvokeMember("ADSPath","GetProperty",$null,$member,$null)
}
}


What am I doing wrong?










share|improve this question

























  • while i have never tried it, i thot that the objects returned by a job where NOT live objects. if that is correct, then your .InvokeMember() call is likely returning garbage since there likely aint anything there to invoke.

    – Lee_Dailey
    Nov 26 '18 at 22:30














0












0








0








I have a working script that gets local Admins on remote servers, but sometimes there's an issue with one of the servers in the list (even though Test-Connection succeeds) that will hang and stops the script from continuing. So I've been looking into using jobs as a means of having a timeout feature if a server takes too long to respond.



In my test script, I'm getting a list of System.__ComObject objects back, which seems promising, but I can't parse them like usual and get error:




Exception calling "InvokeMember" with "5" argument(s): "Method
'System.Management.Automation.PSCustomObject.ADSPath' not found."
At c:timeout.ps1:48 char:3
+ $member.GetType().Invokemember("ADSPath","GetProperty",$null, ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : MissingMethodException


NOTE: For above error, it's repeated for Name, Class and ADSPath (bascially all the invokes I tried.



Here is the script code:



# Test Timeout functionality
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string]$Computer
)

$timeout = 90 ## seconds
$retryInterval = 5 ## seconds
$LocalGroupName = "Administrators"
$group = $null
$members = $null

Write-Host "Working on $($computer)..."

Write-Verbose "Start Job..."
$job1 = {
Param($computer,$localgroupname)

$group =[ADSI]"WinNT://$computer/$LocalGroupName"
@($group.psbase.Invoke("Members"))
}
Start-Job -Name "Members" $job1 -ArgumentList $computer,$localgroupname

$Check_Job = Get-Job -Name "Members"
$timer = [Diagnostics.Stopwatch]::StartNew()

while ($timer.Elapsed.TotalSeconds -lt $Timeout) {
if ($Check_Job.State -eq 'Completed') {
$members = Receive-Job -Name "Members"
break
}

Start-Sleep -Seconds $RetryInterval
Write-Verbose -Message "Waiting [$totalSecs]sec until retry..."
}
$timer.Stop()

if (!$members) {
Write-Host "No members found in the group"
} else {
foreach($member in $members) {
Write-Host "-------------------------------------"
$member.GetType().InvokeMember("Name","GetProperty",$null,$member,$null)
$member.GetType().InvokeMember("Class","GetProperty",$null,$member,$null)
$member.GetType().InvokeMember("ADSPath","GetProperty",$null,$member,$null)
}
}


What am I doing wrong?










share|improve this question
















I have a working script that gets local Admins on remote servers, but sometimes there's an issue with one of the servers in the list (even though Test-Connection succeeds) that will hang and stops the script from continuing. So I've been looking into using jobs as a means of having a timeout feature if a server takes too long to respond.



In my test script, I'm getting a list of System.__ComObject objects back, which seems promising, but I can't parse them like usual and get error:




Exception calling "InvokeMember" with "5" argument(s): "Method
'System.Management.Automation.PSCustomObject.ADSPath' not found."
At c:timeout.ps1:48 char:3
+ $member.GetType().Invokemember("ADSPath","GetProperty",$null, ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : MissingMethodException


NOTE: For above error, it's repeated for Name, Class and ADSPath (bascially all the invokes I tried.



Here is the script code:



# Test Timeout functionality
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string]$Computer
)

$timeout = 90 ## seconds
$retryInterval = 5 ## seconds
$LocalGroupName = "Administrators"
$group = $null
$members = $null

Write-Host "Working on $($computer)..."

Write-Verbose "Start Job..."
$job1 = {
Param($computer,$localgroupname)

$group =[ADSI]"WinNT://$computer/$LocalGroupName"
@($group.psbase.Invoke("Members"))
}
Start-Job -Name "Members" $job1 -ArgumentList $computer,$localgroupname

$Check_Job = Get-Job -Name "Members"
$timer = [Diagnostics.Stopwatch]::StartNew()

while ($timer.Elapsed.TotalSeconds -lt $Timeout) {
if ($Check_Job.State -eq 'Completed') {
$members = Receive-Job -Name "Members"
break
}

Start-Sleep -Seconds $RetryInterval
Write-Verbose -Message "Waiting [$totalSecs]sec until retry..."
}
$timer.Stop()

if (!$members) {
Write-Host "No members found in the group"
} else {
foreach($member in $members) {
Write-Host "-------------------------------------"
$member.GetType().InvokeMember("Name","GetProperty",$null,$member,$null)
$member.GetType().InvokeMember("Class","GetProperty",$null,$member,$null)
$member.GetType().InvokeMember("ADSPath","GetProperty",$null,$member,$null)
}
}


What am I doing wrong?







powershell jobs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 22:33









Ansgar Wiechers

143k13130187




143k13130187










asked Nov 26 '18 at 22:25









NamunaNamuna

853713




853713













  • while i have never tried it, i thot that the objects returned by a job where NOT live objects. if that is correct, then your .InvokeMember() call is likely returning garbage since there likely aint anything there to invoke.

    – Lee_Dailey
    Nov 26 '18 at 22:30



















  • while i have never tried it, i thot that the objects returned by a job where NOT live objects. if that is correct, then your .InvokeMember() call is likely returning garbage since there likely aint anything there to invoke.

    – Lee_Dailey
    Nov 26 '18 at 22:30

















while i have never tried it, i thot that the objects returned by a job where NOT live objects. if that is correct, then your .InvokeMember() call is likely returning garbage since there likely aint anything there to invoke.

– Lee_Dailey
Nov 26 '18 at 22:30





while i have never tried it, i thot that the objects returned by a job where NOT live objects. if that is correct, then your .InvokeMember() call is likely returning garbage since there likely aint anything there to invoke.

– Lee_Dailey
Nov 26 '18 at 22:30












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53490047%2fget-local-admins-on-remote-server-running-as-job%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53490047%2fget-local-admins-on-remote-server-running-as-job%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks