Invoke Command Timeout?

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Cody Everingham Cody Everingham 8 months, 3 weeks ago.

  • Author
    Posts
  • #36576
    Profile photo of Cody Everingham
    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
    Profile photo of Don Jones
    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
    Profile photo of Cody Everingham
    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.

You must be logged in to reply to this topic.