Question

I am trying to run a powershell script in server1 to deploy WSP file present in server2. Here is my code:

$password = ConvertTo-SecureString "password" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("username",$password)
Enter-PSSession -ComputerName server2 -Credential $cred
Add-PSSnapin Microsoft.Sharepoint.Powershell –EA 0
Update-SPSolution -Identity TechSoup.Web.wsp -LiteralPath "C:\Program Files ...Debug\Some.wsp" -GacDeployment 

I am successfully able to enter server2 using the first 3 lines. I now want to run the bottom two lines as administrator on server2 from server1. I am getting this error:

Update-SPSolution : Cannot access the local farm. Verify that the local farm is properly configured, currently available, and that you have the appropriate permissions to access the database before trying again.

Can anyone help me with this ?? I need to deploy the wsp solution remotely.

Was it helpful?

Solution

I have found the answer here:

HERE

I hope this helps someone who needs this.

Here is how it worked for me:

On Client:

Enable-PSRemoting
Enable-WSmanCredSSP -Role "Client" -DelegateComputer clientmachinename -Force

Also, go to gpedit.msc and look at the following policy: Computer Configuration -> Administrative Templates -> System -> Credentials Delegation -> Allow Delegating Fresh Credentials and Allow Delegating Fresh Credentials with NTLM. Enable the state and add SPN to Server List for Remote Server. In our case it will be: WSMAN/clientmachinename. Click Okay, save and exit.

On Server: (Where WSP file is present and needs to be deployed)

Enable-PSRemoting
Enable-WSmanCredSSP -Role Server
winrm set winrm/config/winrs '@{MaxShellsPerUser="25"}'
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="600"}' 

Click Yes/Yes to all till the dialog box appear.

Now Our System is configured for Remote execution of Powershell command.

Once, this is done, go to Client and run this command:

$password = ConvertTo-SecureString "your password" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("username",$password)
Invoke-command -computername yourServerName -credential $cred -authentication CredSSP -scriptblock {Add-PSSnapin Microsoft.Sharepoint.Powershell –EA 0 
Update-SPSolution -Identity yourfile.wsp -LiteralPath "C:\Program Files (x86)\(location of your file)...\yourfile.wsp" -GacDeployment} 

The above script will deploy our wsp file to Server. Make sure that you run these commands in administrator mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top