question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Imported modules that were exported seem to be broken

See original GitHub issue

Exporting a module locally (such as Office 365 remote powershell) and then re-importing it results in the cmdlets in that module being broken (on Mac/Linux, haven’t tested Windows). The error they return is below. If I just connect to the Office 365 powershell session directly without exporting it, it works fine. So it seems to be something with the re-imported module that breaks it?

Steps to reproduce

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential (Get-Credential) -Authentication Basic -AllowRedirection -Name TestTenant
Export-PSSession $Session -OutputModule "path_to_module" -AllowClobber
Import-Module TestTenant -DisableNameChecking -Global

Expected behavior

The imported module should work.

Actual behavior

PS /Users/rfoust> Get-Mailbox
Creating a new session for implicit remoting of "Get-Mailbox" command...
Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in
a pipeline element produced an object that was not valid. It must result in a command name, a script
block, or a CommandInfo object."
At /Users/rfoust/.local/share/powershell/Modules/TestTenant/TestTenant.psm1:18294 char:13
+             $steppablePipeline = $scriptCmd.GetSteppablePipeline($myI ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CmdletInvocationException

Environment data

Name                           Value
----                           -----
PSVersion                      6.1.2
PSEdition                      Core
GitCommitId                    6.1.2
OS                             Darwin 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
rfoustcommented, Feb 13, 2019

@vexx32 Oh wow, doing it that way never occurred to me. Mind blown. 😃 It worked on a quick test! I still need to put that logic in my wrapper function and see how it behaves after the session breaks. But looks promising so far, thanks!

1reaction
vexx32commented, Feb 13, 2019

The basic method I’d probably tackle it from is like this:

# usually these are temp_* for an imported PSSession
$Module = Get-Module -Name $ModuleName 

# single-quotes! Variable names need to be intact
$ModuleScript = [scriptblock]::Create($Module.Definition -replace '<credential_line>','$global:Creds') 

# Create new module from modified script block
$New = New-Module -Name NewModuleName -ScriptBlock $ModuleScript

# remove original copy of the module from the session
Remove-Module $Module.Name 

# import the new module
$New | Import-Module 

This might run into the same issue, but… it’s worth a shot nonetheless. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does import Module from 'module' import when no ...
In older, pre-ES6 node modules usually no default export is defined. Which means that you cannot import them as an ES6 module. Your...
Read more >
@_exported and fixing import visibility - Discussion - ...
The net effect is that some modules end up getting re-exported when you import a library...but it's only those that are needed to...
Read more >
Custom blocks cannot be properly exported and imported
This block is broken or missing. You may be missing content or you might need to enable the original module. Go under Custom...
Read more >
Understanding Modules and Import and Export Statements ...
In this tutorial, you will learn what a JavaScript module is and how to use import and export to organize your code. Modular...
Read more >
CommonJS vs. ES Modules: Modules and Imports in NodeJS
Although at first glance it may seem like module.exports , exports and require are global, actually they are not. CommonJS wraps your code ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found