How to run PS1 file on a Server 2016 from a remote computer?

284 Views Asked by At

i wrote a script for Exchange Management Shell. i've saved the script on the server. my question is: how can i run the script from a remote windows 10 Computer? *regarding to server authentiication - it's O.K for me to write my server Credentials on the script

i've try this script, but it's asking for user and password every time and cannot exeute the file.

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://mailserver/PowerShell/ -Authentication Kerberos -Credential $UserCredential
Import-PSSession $Session
Invoke-Command -ComputerName mailserver -FilePath \\mailserver\c$\Script\MPC3.ps1

EDIT: i want to be able to open the following PS on my Windows computer: MAPILab.Pop3Connector.Shell

Thanks for helping me !

1

There are 1 best solutions below

3
Patrick On

I do not recommend to store credentials inside a script. But here a way of doing it:

$Username = 'username'
$Password = 'passwd' | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object -TypeName 'System.Management.Automation.PSCredential' -ArgumentList $Username, $Password