Skip to content

Starting jobs locally and on remote host can not be done with a single command #17276

Closed
@zamothh

Description

@zamothh

Summary of the new feature / enhancement

Problem

In the case I have multiple servers where I want to run a scriptblock, including the server I am connected on, I am forced to write this over explicit code :
Note : the powershell session is running on ServerB

for ($computer in "ServerA", "ServerB", "ServerC") {
    if ($computer -like $env:computername ) {
        # Computer = ServerB
        $Jobs += start-job -ScriptBlock $ScripBlock
    } else {
        # Computer = ServerA or ServerC
        $Jobs += Invoke-Command -ComputerName $computer -AsJob -ScriptBlock $ScripBlock
    }
}

Reason

  • Start-job does not allow to run jobs on remote host
  • Invoke-Command -ComputerName $env:computername -asjob -ScriptBlock $ScripBlock
    • Requires to be "ran as administrator" to function
      • OR
    • throws an error OpenError: [Hostname] Connecting to remote server Hostname failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
  • Invoke-Command -AsJob -ScriptBlock { dir } does not match required parameter set

Conclusion

This is not new to powershell and I have always found complexity into writing scriptblocks that could run on multiple servers, including the local server I am connected on

Proposed technical implementation details (optional)

As start-job does not require to "run as administrator" I feel like there shouldn't be any restrictions into being able to run

  • Invoke-Command -AsJob -ScriptBlock { dir } which could be, somehow, an alias of start-job
  • Invoke-Command -AsJob -ScriptBlock { dir } -computername $env:computername
    without having to use the 'log on as adaministrator' switch

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugNeeds-TriageThe issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreWG-RemotingPSRP issues with any transport layer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions