0

I have a folder in Sharepoint Server. In the folder, there is a script(.ps1 file), that I can run with powershell.

It works fine with powershell, if I run it when I'm in Sharepoint Server.

But I want to be able to run this script from another computer without connecting to the Sharepoint Server.

How can I make it happen? Thank you.

The script that I want to run without remote desktop connection:

Add-PSSnapin Microsoft.Sharepoint.Powershell
$vessellist = import-csv -Path "\\server\c$\filepathoftheexcel\myexcel.csv"          
#Get the list used to import the data to            
$l = (Get-Spweb "http://server").GetList("http://server/Lists/mylistname")            
foreach($item in $vessellist)            
{     
    //some process

}

Updated1:

I ran this commands from my computer :

$pass = convertto-securestring "password" -asplaintext -force
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "domain\username",$pass

Enter-PSSession -ComputerName servername –Credential $mycred 
Invoke-Command -Computer servername -credential $mycred -Command{ "C:\Users\username\Desktop\folder\addToList.ps1"}

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$farm


cd..
cd Desktop\folder
.\addToList.ps1

I get this error:

Get-SPWeb : 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.

Updated2:

My last command for powershell from my computer is:

$pass = convertto-securestring "password" -asplaintext -force
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "domain\username",$pass

Enter-PSSession -ComputerName servername –Credential $mycred 
Invoke-Command -Computer servername -credential $mycred -Command{ "C:\Users\username\Desktop\folder\addToList.ps1"}

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$farm
cd "C:\Windows\System32\WindowsPowerShell\v1.0"
powershell Set-ExecutionPolicy Unrestricted
powershell Get-ExecutionPolicy


runas /profile /user:domain\username /savecred  C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe  -executionpolicy unrestricted -file C:\Users\username\Desktop\folder\addToList.ps1 -ExecutionPolicy ByPass

After the last command it doesn't give me any message. It just jump the next new line for the new command:

[servername]: PS C:\Windows\System32\WindowsPowerShell\v1.0>

1 Answer 1

-1

Did you try Enable-PSRemoting ? It might help

3
  • Yes. It says WinRM already set up to receive requests on this message. WinRM already is set up for remote management on this machine. But in script I get a list of the SP Server with Get-Spweb. So I need to run "Add-PSSnapin Microsoft.Sharepoint.Powershell" command.
    – e.ozmen
    Commented Feb 12, 2014 at 12:12
  • I add my script to question to help you understand.
    – e.ozmen
    Commented Feb 12, 2014 at 12:17
  • @keerthi, Please provide more details for your answer. Commented Feb 13, 2014 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.