Summary
I am currently centralizing powershell scripts. Where a significant amount of users can access these scripts with implicit remoting.
Question:
Is it more efficient to use psm1 over ps1? Given the structure of the setup and scripts from below?
Example script to automate implicit remoting: (Please observe the imported modules are ps1)
$poshSession = New-PSSession -ComputerName serverA -Authentication Kerberos -ConfigurationName poshconfig
Set-Alias -Name rs -Value Resolve-RemotingSession -Description 'Resolves and imports sessions and obtains specific commands'
function Resolve-RemotingSession
{
# Import Modules
Invoke-command -ScriptBlock { Import-Module -Name 'ModuleA.ps1' } -Session $poshSession
Invoke-command -ScriptBlock { Import-Module -Name 'ModuleB.ps1' } -Session $poshSession
Invoke-command -ScriptBlock { Import-Module -Name 'ModuleC.ps1' } -Session $poshSession
Invoke-Command -ScriptBlock { Import-Module -Name 'ModuleD.ps1' } -Session $poshSession
Import-PSSession -Session $poshSession -commandname *CommandA,CommandB,CommandC,CommandD* -AllowClobber
}
Example of one of the Imported Scripts... Please note that each ps1 script has about 15 to 20 functions structured similar to the following:
function Get-FooBarA{
param(
[switch]$Search,
[string]$Term
)
$foobarResults = Invoke-Restmethod -method Get -Uri www.fooA.com/$Search/$term
$foobaresults.Something
}
function Get-FooBarB{
param(
[switch]$Search,
[string]$Term
)
$foobarResults = Invoke-Restmethod -method Get -Uri www.fooB.com/$Search/$term
$foobaresults.Something
}
To my knowledge this setup can be resource intensive where I am forcing the user to import the script each time they setup the session by using a .ps1 script.
If I decide to user a .psm1 file extension (convert these to modules) is there a way to keep these modules persistently imported so that I can remove the following command from the script that initiates the PS session?
Invoke-command -ScriptBlock { Import-Module -Name 'ModuleA.ps1' } -Session $poshSession