How do I start a Powershell session with all imported modules?

I have many modules that make my life easier in a specific folder.

Question : What is the best practice for starting a Powerhsell session that has imported all these modules and functions ready to use?

Thank!

+3


source to share


1 answer


you can create a profile on a network share \\server\share\commonProfile.ps1

in this profile you define your path to the shared folder

if($env:PSModulePath -match "\\\\server\\share\\modules" -eq $false){
    $env:PSModulePath = $env:PSModulePath + ";\\server\share\Modules"
}

      



Copy your modules to \\server\share\Modules

, you should now be able to do

$rs=new-pssession $computername
icm -Session $rs -ScriptBlock{. \\server\share\commonProfile.ps1} #dot source the profile
etsn $rs #enter remote session

#your modules should now be availables in the remote session :
get-module -listavailable

      

+4


source







All Articles