Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSFramework and JEA on Windows PowerShell 5.1 #315

Closed
constantinhager opened this issue May 17, 2019 · 11 comments
Closed

PSFramework and JEA on Windows PowerShell 5.1 #315

constantinhager opened this issue May 17, 2019 · 11 comments
Labels
Status: Not Quite Resolved After All When you've been overconfident about having fixed something ... Type: Bug

Comments

@constantinhager
Copy link

Hi,

I use your module in a JEA configuration on Windows PowerShell 5.1

PS C:\Windows\system32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.2636
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.2636
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

It is a Server 2016.

If I use the following Code to enter a Session

Enter-PSSession -ComputerName server -ConfigurationName confname

I will get the following error:

Enter-PSSession : One or more errors occurred processing the module 'PSFramework' specified in the InitialSessionState
object used to create this runspace. See the ErrorRecords property for a complete list of errors. The first error was:
The term 'Import-PowerShellDataFile' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Enter-PSSession -ComputerName xx -ConfigurationName xx...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (:) [Enter-PSSession], RunspaceOpenModuleLoadException
    + FullyQualifiedErrorId : ErrorLoadingModulesOnRunspaceOpen

My Session Configuration looks like this:

@{

# ID used to uniquely identify this document
GUID = '3e34082a-94cb-4e31-8bb5-c30c55f52d83'

# Author of this document
Author = 'xxx'

# Description of the functionality provided by these settings
# Description = ''

# Company associated with this document
CompanyName = 'xx'

# Copyright statement for this document
Copyright = '(c) 2019 xx. All rights reserved.'

# Modules to import when applied to a session
ModulesToImport = 'PSFramework'

# Aliases to make visible when applied to a session
# VisibleAliases = 'Item1', 'Item2'

# Cmdlets to make visible when applied to a session
VisibleCmdlets = 'PSFramework\*'

# Functions to make visible when applied to a session
VisibleFunctions = 'PSFramework\*'

# External commands (scripts and applications) to make visible when applied to a session
# VisibleExternalCommands = 'Item1', 'Item2'

# Providers to make visible when applied to a session
# VisibleProviders = 'Item1', 'Item2'

# Scripts to run when applied to a session
# ScriptsToProcess = 'C:\ConfigData\InitScript1.ps1', 'C:\ConfigData\InitScript2.ps1'

# Aliases to be defined when applied to a session
# AliasDefinitions = @{ Name = 'Alias1'; Value = 'Invoke-Alias1'}, @{ Name = 'Alias2'; Value = 'Invoke-Alias2'}

# Functions to define when applied to a session
# FunctionDefinitions = @{ Name = 'MyFunction'; ScriptBlock = { param($MyInput) $MyInput } }

# Variables to define when applied to a session
# VariableDefinitions = @{ Name = 'Variable1'; Value = { 'Dynamic' + 'InitialValue' } }, @{ Name = 'Variable2'; Value = 'StaticInitialValue' }

# Environment variables to define when applied to a session
# EnvironmentVariables = @{ Variable1 = 'Value1'; Variable2 = 'Value2' }

# Type files (.ps1xml) to load when applied to a session
# TypesToProcess = 'C:\ConfigData\MyTypes.ps1xml', 'C:\ConfigData\OtherTypes.ps1xml'

# Format files (.ps1xml) to load when applied to a session
# FormatsToProcess = 'C:\ConfigData\MyFormats.ps1xml', 'C:\ConfigData\OtherFormats.ps1xml'

# Assemblies to load when applied to a session
# AssembliesToLoad = 'System.Web', 'System.OtherAssembly, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

}

If I try to import another module but not PSFramework the Session works.

I also wrote that there is a bug with Windows PowerShell and JEA with Import-PowerShellDataFile (PowerShell/JEA#42). This error only happens if I import the PSFramework Module.

Can you please take a look at this?

Greetings
Constantin

@FriedrichWeinmann
Copy link
Member

Hi Constantin,

will do, but - this is important - don't blanket whitelist PSFramework in JEA!
Some commands would allow escaping the JEA constraints (notably: Select-PSFObject, Invoke-PSFCommand, some of the other commands that register a scriptblock).

It appears to have issues with Import-PowerShellDataFile ... hm, will look into it for sure.

Cheers,
Fred

@constantinhager
Copy link
Author

Thank you for pointing that out, but I only need Write-PSFMessage and Set-PSFLoggingProvider because I use your logging system.

@constantinhager
Copy link
Author

Status Resolved?

@FriedrichWeinmann
Copy link
Member

FriedrichWeinmann commented May 22, 2019

Heya @constantinhager ,
yepp, is resolved as of 1.0.19, which is now released.
Actually, I was tagging stuff as final checkoff (I use issues as my todo list).
Problem: PackageManagement had a buggy build and was hanging my build pipeline. That's resolved now and 1.0.19 is now available, but added a multi-hour gap to things.

Would you mind giving the latest version a try?

@constantinhager
Copy link
Author

Hi @FriedrichWeinmann,
Kind Of. If I import It in Modules To Import It works.
If I try to import explicitly Write-PSFMessage in VisibleCmdlets for example I get the following Error again.

Enter-PSSession : One or more errors occurred processing the module 'PSFramework' specified in the InitialSessionState
object used to create this runspace. See the ErrorRecords property for a complete list of errors. The first error was:
The term 'Import-PowerShellDataFile' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Enter-PSSession -ComputerName xx -ConfigurationName xx...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (:) [Enter-PSSession], RunspaceOpenModuleLoadException
    + FullyQualifiedErrorId : ErrorLoadingModulesOnRunspaceOpen
```powershell

@FriedrichWeinmann
Copy link
Member

Crazy stuff - looks like more troubleshooting is necessary :(

@FriedrichWeinmann FriedrichWeinmann added Status: Not Quite Resolved After All When you've been overconfident about having fixed something ... and removed Status: Resolved labels May 22, 2019
@FriedrichWeinmann
Copy link
Member

Hi @constantinhager,

I've just made the time to do a full reproduction test and I cannot reproduce the issue.
Can you re-validate the PSFramework version on the targeted endpoint?

Cheers,
Fred

@constantinhager
Copy link
Author

Hi @FriedrichWeinmann,
I have indeed 1.0.19 installed. But I noticed that error with the Import-PowerShellDataFile occours everytime i activate visiblecmdlets or visiblefunctions. If I just do ModulesToImport with the PSFramework everything works fine. I also import the ActiveDirectory module into the JEA Session. If I have any command in visiblecmdlets or visiblefunctions It errors out with the Import-PowerShellDataFile so that's not your fault I think. It is a Windows PowerShell issue.

Cheers,
Constantin

@FriedrichWeinmann
Copy link
Member

Hm ... still having trouble following your observed issues :(
Would you mind packaging up a fully functional example JEA setup that reproduces the issue and sending it to:

'H4sIAAAAAAAEAG2PwWoCMRRF9wX/IWRvkhFXJTPoUhAFR7qRLqaZNyYySSTvic7fN3WwFuoql3M5Nzy9/Toh+4CELoaSF6IQShSc3XwfsOSW6PwuJRoLvkHhnUkRY0fCRC/P8Zo9C30vZ0rNpZrzavLGmM6bbAfdqi25GlGG+80/9kOrekACL7IDhg6fWu5ftMuUmuF1NYrPLqfNI67rP0ZddclBm5yx4gou+CaExfOGKdKF6NgkEi1oWf/OPUa0zF/ldH+x+gbunMJSOgEAAA==' | ConvertFrom-PSFClixml

@constantinhager
Copy link
Author

Sent It to you. Notice: I have configured the endpoint with a RunAsAccount to get access to my domain.

@FriedrichWeinmann
Copy link
Member

Heya, just a headsup:
The current release of PSFramework works around using the command Import-PowerShellDataFile, so this should be fixed now.
Can you confirm that @constantinhager ?
Also: It now includes Import-PSFPowerShellDataFile, offering the same service for other code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Not Quite Resolved After All When you've been overconfident about having fixed something ... Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants