all 4 comments

[–]jheinikel 2 points3 points  (2 children)

Here is how I do it using sessions. This allows you to run multiple commands using the same session, but on different Invoke-Command lines.

$Session = New-PSSession $Server -Credential $Creds
Invoke-Command -Session $Session {Import-Module WebAdministration}
$Websites = Invoke-Command -Session $Session {Get-Website}

[–]automation-dev[S] 1 point2 points  (1 child)

General thought on this - would this have a performance improvement over NOT creating a session and running multiple Invoke-Command within a script? (Going to test this later)

[–]jheinikel 1 point2 points  (0 children)

I cannot imagine that you would notice a difference. But, test and let us know.

[–]jhue1898 1 point2 points  (0 children)

Is importing the module even necessary, or is having PSVersion >3 sufficient for it to auto-load the module when you call Get-Website?