Invoke Command Timeout?

This topic contains 3 replies, has 3 voices, and was last updated by  chad 9 months, 1 week ago.

  • Author
    Posts
  • #36576

    Cody Everingham
    Participant

    So This script kind of works...on half of the targets...

    1st of all know that WINRM is enabled on all the machines I'm working with. and I'm running the following script.

    function getUserInput() {
    $targetPassword = "password"
    $targetUserName = "domain\username"
    massLogin
    }

    function massLogin() {
    $serverList = Get-Content import.txt
    foreach ($server in $serverList){
    Invoke-Command -ComputerName $server -ScriptBlock {
    param($targetUserName,$targetPassword)
    Try {Set-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value 1}
    Catch {New-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -PropertyType String -Value 1}
    Try {Set-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value $targetUserName}
    Catch {New-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -PropertyType String -Value $targetUserName}
    Try {Set-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value $targetPassword}
    Catch {New-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -PropertyType String -Value $targetPassword}
    Restart-Computer -Force
    } -ArgumentList $targetUserName, $targetPassword
    }
    }

    getUserInput

    This hits 50% of em every time but for the others I get:

    [110H31] Connecting to remote server 110H31 failed with the following error message : The client cannot connect to the destination specified in the request.
    Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on
    the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the
    WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo : OpenError: (110H31:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken

    I believe this is because it only tries to connect to those devices for about a second. Is there a way to make it so it tries for like 3? Or is it possible that I'm completely wrong about the issue?

  • #36623

    Don Jones
    Keymaster

    Well, let's basic t'shoot it. Is it always the same machines that fail? Can you connect to one manually? Does it seem to take longer than normal? The error suggests that the WinRM service didn't respond at all, like, meaning the port wasn't even open. If that's not the case, is there anything on the network that could be making it seem otherwise?

  • #36667

    Cody Everingham
    Participant

    What I ended up doing is throwing out a GPO that would ensure the service "winrm" was set to automatic, we have the exact same image on all of our machines (ghost) so I'm not sure what to make of it. Anyway I resolved the issue by using a third party program that sent out commands through it to clusters of computers, and that works at 100%. I just try to use powershell when ever I can.

  • #63976

    chad
    Participant

    i'm having a similar issue as Cody presented...I've checked the simple things, i can ping, RDP, etc. I do wonder if there is more of a delay or slow connection to certain computers and yes it seems to be the same ones all the time...

    here's the code (it's only a portion of it...) :

    function Get-SOEInstalledSoftware {
    Get-ChildItem HKLM:\SOFTWARE\Microsoft\windows\CurrentVersion\Uninstall,HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
    Get-ItemProperty |
    Select-Object DisplayName,Publisher,DisplayVersion,InstallDate,UninstallString, @{L='Guid';E={Split-Path $_.PSPath -Leaf}}
    }

    Function SoftLookupCred {
    foreach ($StrComputer in $colComputers){
    $SoftwareItems1 = Invoke-Command -ComputerName $StrComputer -ScriptBlock ${function:Get-SOEInstalledSoftware} -Credential $me

    now if i break it down, and run the second function outside of the script as in individual commands...ie (the first function is already loaded):

    $SoftwareItems1 = Invoke-Command -ComputerName problem_computer -ScriptBlock ${function:Get-SOEInstalledSoftware} -Credential $me

    after it completes (no errors) then when i look at what $SoftwareItems1 contains, it's empty.

    i'm wondering if it's because it takes too long to enumerate the registry keys.

    by the way if I get on one of the problem computers i can set the first function in the code above and it will display the expected information.

You must be logged in to reply to this topic.