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!

Michele
  • 3,617
  • 12
  • 47
  • 81
  • You are going to need the modules. Have a look at `PnP-PowerShell` if you don't want to run the SharePoint installer. – Drew Nov 20 '18 at 22:11

1 Answers1

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

Mike Twc
  • 2,230
  • 2
  • 14
  • 19
  • 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. – Michele Nov 21 '18 at 13:13
  • 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 – Mike Twc Nov 21 '18 at 14:43
  • 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 – Michele Nov 21 '18 at 14:47
  • I tried the dir above Forms as well and it had UnauthorizedAccessException too – Michele Nov 21 '18 at 14:48
  • Strange, are you logged as a user that have access? Or you don't use AD authentification? – Mike Twc Nov 21 '18 at 14:50
  • We use AD authentication but I think it's not getting to powershell. I can just open the link in my browser and see powershell and the files. I can get to that dir in file exploerer too like I said. – Michele Nov 21 '18 at 14:52
  • Well, since you get Permission Denied I'd think you user don't have access to that folder. If you need use some other credentials check this https://stackoverflow.com/questions/303045/connecting-to-a-network-folder-with-username-password-in-powershell – Mike Twc Nov 21 '18 at 14:59