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 $remotesrvEnjoy the Powershell!