0

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!

1
  • You are going to need the modules. Have a look at PnP-PowerShell if you don't want to run the SharePoint installer. Commented Nov 20, 2018 at 22:11

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

7 Comments

File Explorer shows me the contents of the Forms dir, but when I try to connect to the AllItems.aspx, it's asking me what I want to open it with. It's File type asp.net Server Page. I'm not sure if copying that AllItems.aspx will copy the sharepoint file contents. When I'm in sharepoint, going to that location gives me a listing of about 10 files in the browser.
You don't need to connect to Allitems or anything. Just locate the folder you need in file explorer, go one level up, go to folder properties, copy location. Then go to powershell, type cd "thatFolderLocation", then ls. Do you see your files after it? You can put the screenshot of what you doing if having problems
When I try to cd that location in powershell it says access denied. Permission denied UnauthorizedAccessException. It must be powershell doesn't have my login but file manager knows I'm logged in so I can see the dir where AllItems is
I tried the dir above Forms as well and it had UnauthorizedAccessException too
Strange, are you logged as a user that have access? Or you don't use AD authentification?
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.