Reputation: 3881
I'm writing a powershell script to copy files from sharepoint to a windows computer location. I don't want to install sharepoint on a windows computer to run this powershell script. We only need it on the server that runs our sharepoint. The purpose of my script is to copy files from sharepoint to a windows computer as backup.
I'm following this example. However, when I run it (with the add-psSnapin) , I get:
"Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.SharePoint.PowerShell' is not installed on this computer."
I was looking at this article, and it seemed to take the Enable-PSRemoting, which I added in my script.
This is my script to far, which is just like the link I gave above:
#run 64 bit powershell version as administrator (doing this): https://stackoverflow.com/questions/19055924/how-to-launch-64-bit-powershell-from-32-bit-cmd-exe
Set-ExecutionPolicy RemoteSigned #permission to run scripts
Enable-PSRemoting
Get-PSSnapin -Registered | Add-PSSnapin -Passthru
#Add-PSSnapin Microsoft.SharePoint.PowerShell
$tempSource = "http://sharepoint.college.edu/sites/Disaster%20Plan/Forms/AllItems.aspx"
$ToLocation = "C:\Users\mcl8\Documents\2018\powershellFiles\toLoc\"
$web = Get-SPWeb -Identity "http://sharepoint.college.edu/sites/Disaster%20Plan/Forms/"
$list = $web.GetList("http://sharepoint.college.edu/sites/Disaster%20Plan/Forms/AllItems.aspx")
function ProcessFolder{
param($SourceUrl)
$folder = $web.GetFolder($SourceUrl)
foreach ($file in $folder.Files) {
#Ensure destination dir
$destinationFolder = $destination + "/" + $folder.Url
if (!(Test-Path -path $destinationFolder))
{
$dest = New-Item $destinationFolder -type directory
}
#Download file
$binary = $file.OpenBinary()
$stream = New-Object System.IO.FileStream($destinationFolder + "/" + $file.Name), Create
$writer = New-Object System.IO.BinaryWriter($stream)
$writer.Close()
}
} #ProcessFolder
#################start here##################################
#run this as administrator
#Download root files
ProcessFolder($list.RootFolder.Url)
#Download files in folders
foreach ($folder in $list.Folders) {
#ProcessFolder($folder.Url)
}
It's failing on Get-SPWeb as follows:
Get-SPWeb : The term 'Get-SPWeb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I tried uncommenting the Add-PSSnapin line, but get this failure:
Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.SharePoint.PowerShell' is not installed on this computer.
But, like I said, I don't want to install Sharepoint on my computer.
Any ideas how to use the sharepoint add-ins? Thanks!
Upvotes: 0
Views: 2080
Reputation: 2355
If you just need to copy files, there is no really need for any special script or module. Usually you can treat sharepoint libraries as network folders. Copy this to the file explorer and see if you can open it.
\\sharepoint.college.edu\DavWWWRoot\sites\Disaster%20Plan\
Or you can also open your library location in internet explorer, there should be a button like "open as folder" or something like that. Then all you need is Copy-Item
Upvotes: 0