GithubHelp home page GithubHelp logo

Comments (12)

dcmacdonald avatar dcmacdonald commented on September 26, 2024 1

I could help with server tests if you want.

from invoke-commandas.

mkellerman avatar mkellerman commented on September 26, 2024

I've installed Powershell 7.0.0-rc.1 on both my client (source) and my server (destination).

Every time i execute Invoke-CommandAs, it returns PSVersion 5.1... can't get it to run on 7 in my remote session.. am i missing something?

Code i use to test:

Import-Module .\Invoke-CommandAs -Force

If (!$Credential) { $Credential = Get-Credential '.\Administrator' }
If (!$PSSession) { $PSSession = New-PSSession -ComputerName '192.168.86.80' -Credential $Credential }

$ScriptBlock = { 

    Write-Warning "Computer  : $($Env:ComputerName)"
    Write-Warning "PSVersion : $($PSVersionTable.PSVersion.ToString())"

    [System.Security.Principal.Windowsidentity]::GetCurrent()
    
}

Invoke-CommandAs -Session $PSSession -ScriptBlock $ScriptBlock -ASSystem

Result:

RunspaceId         : ee68d0d2-4a5d-4f4d-afe8-a39bea22cbba
AuthenticationType : NTLM
ImpersonationLevel : None
IsAuthenticated    : True
IsGuest            : False
IsSystem           : True
IsAnonymous        : False
Name               : NT AUTHORITY\SYSTEM
Owner              : S-1-5-18
User               : S-1-5-18
Groups             : {S-1-1-0, S-1-5-32-545, S-1-5-6, S-1-2-1…}
Token              : 2116
AccessToken        : Microsoft.Win32.SafeHandles.SafeAccessTokenHandle
UserClaims         : {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: NT AUTHORITY\SYSTEM, http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid: S-1-5-18,
                     http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-1-0, http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-5-32-545…}
DeviceClaims       : {}
Claims             : {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: NT AUTHORITY\SYSTEM, http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid: S-1-5-18,
                     http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-1-0, http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid: S-1-5-32-545…}
Actor              :
BootstrapContext   :
Label              :
NameClaimType      : http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
RoleClaimType      : http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid

WARNING: Computer  : MK-TESTSERVER
WARNING: PSVersion : 5.1.14393.3383

What am i doing wrong?

from invoke-commandas.

janegilring avatar janegilring commented on September 26, 2024

From within Windows PowerShell on your target machine (server), run Get-PSSessionConfiguration and you will see the available session configurations.
Currently, the microsoft.powershell endpoint is the default, even when remoting from PowerShell Core or PowerShell 7.
I believe Steve Lee on the PowerShell mentioned on Twitter recently that they plan to change this behaviour in PowerShell 7.1, so that the latest PowerShell 7.x session configuration will be the default.

Until then, you can simply specify -ConfigurationName when using Invoke-Command/New-PSSession:

Invoke-Command -ComputerName . {$PSVersionTable} -ConfigurationName PowerShell.7.0.0-rc.2

This will of course require that Enable-PSRemoting has been run in PowerShell 7.

from invoke-commandas.

germeshausen avatar germeshausen commented on September 26, 2024

Had been a while ago and i'd like to ask if there is something in the pipe regarding powershell 7.2.

from invoke-commandas.

mkellerman avatar mkellerman commented on September 26, 2024

I have t had an opportunity or requirement to do any work on this for my work. If someone cares to give it a try and submit a PR, I’d gladly test and merge this in.

from invoke-commandas.

pluto00987 avatar pluto00987 commented on September 26, 2024

However, in PowerShell 7 it seems like the PSScheduledJobs [sic] module is back, but there is a different error:

I think this was a false alarm. As of Powershell 7.4 that module is not available and shows a similar error as mentioned under 6.x. For additional explanation it suggests running Import-Module which says this:
Module 'PSScheduledJob' is blocked from loading using Windows PowerShell compatibility feature by a 'WindowsPowerShellCompatibilityModuleDenyList' setting in PowerShell configuration file.

See also PowerShell/PowerShell#12743 (comment)

So the underlying issue for PS 6 and 7 support is that the PSScheduledJob module is no longer available.

Edit: Corrected module name PSScheduledJob singular, not PSScheduledJobs

from invoke-commandas.

mkellerman avatar mkellerman commented on September 26, 2024

Has anyone worked on this? Is there a fix?

from invoke-commandas.

danubie avatar danubie commented on September 26, 2024

Within the last days I'm looking for a solution on that issue.

Due to the fact, that scheduled jobs are not supported in PSCore, I'll trying the following workaround:

  • Issue the scriptblock as scheduled task
  • store the result in a temp file (serialized to be compatible with 5.1)
  • return the result of that file

On my home Win10 it already looks promissing. But I have to look for the opportunity to test it with Windows server releases local and via remote sessions.

Additionally, I would like to upgrade tests to Pesterv5 syntax.

from invoke-commandas.

danubie avatar danubie commented on September 26, 2024

Thanks for your offer. I managed to get a local container running for first server tests. If it's ready, I'll come back to it.

from invoke-commandas.

danubie avatar danubie commented on September 26, 2024

@dcmacdonald : I've prepared a first version of my idea of supporting PS7 (https://github.com/danubie/Invoke-CommandAs/tree/PS7-support).

What it does: To replace the missing 'Register-ScheduledJob' my solution

  • creates a temp. file containing the script parameters
  • creates a temporay file containing an intermediate scriptblock
  • then schedules a task to execute the intermediate script
    • this executes the custom scriptblock, captures pipeline output and stores results to be returned

Open issue:
scriptblock haveing $using. I did not use this kind of scriptblock feature with Invoke-CommandAs, Maybe @mkellerman has an example for me.

I would greatly appreciate tests by you. Local tests using the powershell core container and a test system at our company did quite well.

@mkellerman: Is this idea for supporting PS7 ok for you?

Thanks in advance,
Wolfgang

from invoke-commandas.

mkellerman avatar mkellerman commented on September 26, 2024

@danubie, nice work! I would recommend not using files writen to disk for the scriptblock and parameters. I'll need some time to evaluate (which i'm unfortunatly limited on).

from invoke-commandas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.