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>