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?
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
New-Module. I found now Invoke-Expression, which seems to be doing what I needed learn.microsoft.com/en-us/powershell/module/…
Import-Module -Name $s?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