PowerShell Direct within JEA Session


My searching skills seem to be failing me today. I have a Hyper-V Host with virtual machines on multiple domains. I want to use PowerShell Direct to connect to the VMs and execute cmdlets within the VM. For example connect to a VM and run Get-ADUser to get a list of users. That is pretty easy. However I want to try doing this from a type of SAW and connecting to the Hyper -V host through a JEA Endpoint.

I setup a JEA Endpoint and when connecting I can get list of VMs and do basic VM management. But if i enable the Guest Service Interface on a virtual machine and then attempt to run Invoke-Command -VMName $VM.Name -Credential $Credential -ScriptBlock {Cmdlet here}, i am getting an error about unable to convert a system.string to a scriptblock.

I have tried changing the Language in my JEA Endpoint to FullLanguage to test if that would work, but I still cant get it to work. Is there a resource that discusses using Invoke-Command for PowerShell Direct via a JEA Endpoint?

  • Go figure. When you have been banging your head against your desk for a week and finally decide to ask for some actual help, after asking for help you stumble across a solution.

    What I ended up doing is nesting invoke-commands. This seems to have worked.

    $Session = New-PSSession -ComputerName $VM.ComputerName -ConfigurationName TestJEA -Name $VM.ComputerName
    $AllUsers = Invoke-Command -Session $Session -ArgumentList $VM,$Credential -ScriptBlock {
        Invoke-Command -VMName $VM.Name -Credential $Credential -ScriptBlock {
            Get-ADUser -Filter "Enabled -eq '$True'" -Properties Mail,CanonicalName,EmployeeId