Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Use local profile within powershell remoting

$
0
0

Hi guys!

I spent a lot of time to find a solution below :) 

If you want to use your local powershell profile within powershell remote session (that is not supported by default due to security reason), use this statement:

#create remote session with CredSSP authentication (for "second-hop" functionality)

$remotesrv = New-PSSession -ComputerName remotesrv.contoso.com -Credential "admin@contoso.com" -Authentication Credssp

#get your local profile

$myprofile = Get-Content C:\Users\admin\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

#copy profile to remote server through remote session created above

Invoke-Command -Session $remotesrv -ScriptBlock { 
        param ($psprofile)
        Set-Content -Path C:\Users\admin\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 -Value $psprofile
    } -ArgumentList (,$myprofile)

#And execute it

Invoke-Command -Session $remotesrv {$profile="C:\Users\admin\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"}
Invoke-Command -Session $remotesrv {. $profile}

#And finally, enter the remote session

Enter-PSSession $remotesrv

Enjoy the Powershell!



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>