1

I have a PowerShell script stored as a variable in memory:

$v = Invoke-WebRequest -Uri http://url/with/module.ps -UseBasicParsing
$s = $v.toString()

I'd like to now do something like Import-Module $s. Is this possible?

2
  • 2
    Have you tried Import-Module -Name $s? Commented Feb 8, 2023 at 21:27
  • @DavidPostill Unfortunately I'm unable to do this PS C:\Users\dir> Import-Module -Name $s Import-Module : Illegal characters in path. At line:1 char:1 + Import-Module -Name $s + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Import-Module], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.I mportModuleCommand Commented Feb 10, 2023 at 20:45

1 Answer 1

0

The New-Module cmdlet will provide the functionality you need. I've included a commented out offline example to demonstrate usage:

$v = Invoke-WebRequest -Uri http://url/with/module.ps -UseBasicParsing
$s = $v.toString() 
#$s = {function Hello {"Hello!"}} #Offline Example
New-Module -ScriptBlock $s -name GreetingModule | Import-Module
1

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.