Moving Document Library to a subsite in SharePoint - powershell

Currently, we have Document Libraries created in SharePoint Online and would like to move them using Powershell to its own Subsite. The reason we would like to move them is that we would like to keep the version history. Since we are dealing with 1000s of files, I would like to use Powershell to complete this task.
I am currently connecting to my SharePoint site using:
Connect-PnPOnline -Url "Sitename" -UseWebLogin
Here is where I need assistance. I am trying to use Move-PnPFolder but I am not sure how to write a command that would define the source, destination, and move of all files in the document library to a subsite that I have manually created.

Here you need to mix of PnP and CSOM PS script... the normal way how we get the SharePoint list items... we need read the the list items then inside the foreach loop you need to call the below command : Move-PnPFolder -Folder 'Shared Documents/Reports/2016/Templates' -TargetFolder 'Shared Documents/Reports' Something like below :
foreach ($oneFolder in List. Folders) { Move-PnPFolder -Folder 'Shared Documents/Reports/2016/Templates' -TargetFolder 'Shared Documents/Reports' }
Note :
In the above command from the $oneFolder property you will get the source folder URL and you already know the target folder location.
This is just sample code to present the concept.

Related

SharePoint Online : manage folder permission with PowerShell

I'm trying to write a Powershell script to grant user permission to a sub-folder in our SharePoint online site. I tried the solutions from the similar questions already open but without success.
I've got an online SharePoint site : https://xxx.sharepoint.com/sites/MySharePoint
In this SharePoint site I've got a library called Test which contains 2 sub-folders Test1 and Test2
I want the user "adtest#x.com" to be granted access to Test1 only in read/write (i.e. contributor).
I used the following code :
Connect-PnPOnline -Url $SiteURL -Credentials $psCred
$folder = Get-PnPFolder -URL "https://xxx.sharepoint.com/sites/MySharePoint/Test/Test1"
Set-PnPfolderPermission -list "Test" -identity $folder -User "adtest#x.com" -AddRole "Contribute"
When I run these commands, on the last step I get an error which translates as : "Impossible to find the level of authorization". My system is in French so I had to translate the message.
I tried the commands found from the other questions on the site but none worked.
Has anybody any idea on the issue ?
Thanks !
Fred
In the pnp documention the identity is always the server relative path.
Try that, just use as identity:
"/Sites/MySharePoint/Test/Test1"
try set the exact name of the permission role. Check it in the advanced permission level.
System need the name in french language resp. in the language of site collection, not english. Example in slovak language which i use

Create Folder on Users' Mailboxes

I would like to create a remote folder inside Inbox with this command wit o365 exchange when execute the following command:
New-MailboxFolder -Parent 'username#domain.com:\Inbox\Folder1' -Name 'Folder1.1'
However, this command cannot be used to create folders on other user’s mailbox.
The error is:
The specified mailbox “username#domain.com” doesn’t exist
What's the exactly problem with this command? Anybody know any Workaround? Thanks!
The cmdlet you're trying to use is not supposed to work for mailboxes other than your own (even if you have proper rights). From the documentation:
Use the New-MailboxFolder cmdlet to create folders in your own mailbox. Administrators can't use this cmdlet to create folders in other mailboxes (the cmdlet is available only from the MyBaseOptions user role).
Some possible workarounds are:
Use Create MailFolder from Graph API
Use MFCMAPI (probably not trivial to be automated)
More detailed description can be found here.

How to Export and Import sharepoint subsite documnet library in Sharepoint 2013?

Please help me, for this i'm using power shell command as
Export-SPWeb "http://iicss89:5555" -itemurl "/HelpFiles" -path "c:\helpdocument.cmp" -IncludeVersions All
it is working for main site document library properly but for subsite it is not working.
for subsite i used below command but it shows error
Export-SPWeb -Identity "http://iicss89:5555/Physics" -itemurl "/HelpFiles" -path "c:\helpphydocument.cmp" -IncludeVersions All
Thanks
ItemUrl parameter must be server relative url. You need to remove the leading slash.
So it should be like this;
-itemurl "HelpFiles"

Sitecore download media folder with powershell

I have a requirement to remove several PDFs from specific folder our Sitecore media library, possibly over 1000 documents. We need to maintain the file names of these PDFs and would prefer to maintain the "file structure/hierarchy" of these documents.
We have tried using the Sitecore Powershell Extensions "Download" feature, but it does not appear to download the PDFs, only the content items themselves. We can create a package, but the folder that contains the resulting PDFs have had their file names replaced with GUIDs.
Is there a PS script available or any other way to do a bulk download of these media library PDFs?
P.S. I am a Powershell neophyte, so please be gentle.
Sounds like you need to use the Send-File command. When executed on a media library item, it allows you to download the associated blob stored in that item.
Example:
PS master:\>Get-Item "master:\media library\files\pdfs\mypdffile" | Send-File -Message "PDF Download"
You can pass -NoDialog to it so the user is not propmted each time.
So for multiple files you can do:
Get-Item -Path master -Query "/sitecore/#media library#/files//*[##templatename='Pdf']" |
Send-File -NoDialog
I can't see performance being great with 1000's of files for that tho. Also it will not keep the path, all files will be saved directly to your Downloads folder.
Perhaps you may be interested in using the download capability through SPE Remoting. This is an alternative solution that operates outside of Sitecore and connects through the web service.
Sample script for downloading:
https://github.com/SitecorePowerShell/Console/blob/master/Modules/Remoting%20Tests%20-%20Download%20with%20RemoteScriptCall.ps1
Book details on getting setup:
https://sitecorepowershell.gitbooks.io/sitecore-powershell-extensions/content/remoting.html

upload site template wsp file powershell

I am using SharePoint 2013 and i want to create some spweb from a site template...
I have created a site and added my desired content and i saved that site as template, then went to solution gallery and downloaded the .wsp file.
Now, i need to create a new site collection with some subsites which are based on that template, and to do so i think need to upload the .wsp file to the solution gallery the way i can find the newly saved template, and i need to do that from PowerShell !
I tried 2 ways,
First,
I tried to add-spsolution and install-spsolution like following
Add-SPSolution -LiteralPath $SPIntranetTemplateFilePath
Install-SPSolution -Identity SPITemplateFile.wsp -CompatibilityLevel 15 -force
but i don't find the .wsp in the solution gallery and the template is not in templates list...
I tried to use Install-SPWebTemplate but this command is not recognized as a cmdlet in my PowerShell (I have added Add-PSSnapin Microsoft.SharePoint.PowerShell)
I have used this too
## SharePoint DLL
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
Can anyone help me to use my WspFile the way i can create subsites based on my template ?
After Add-SPSolution try Install-SPSolution
http://technet.microsoft.com/en-us/library/ff607534(v=office.15).aspx
I think you need to add it as a sandboxed user solution for it to show up in the site collection's solution gallery. This approach worked for me.
$theSite = Get-SPSite "http://server/pathto/site"
# add the solution to the sandbox
Add-SPUserSolution (Resolve-Path .\relativePathTo.wsp) -Site $theSite
# get the user solution and activate it for the site
$customSolution = Get-SPUserSolution -Site $theSite | ? { $_.Title -match "Custom Template Title" }
Install-SPUserSolution $customSolution -Site $theSite
Once you have the sandboxed solution installed, the trick to using it to create a subsite is to use the object model to grab the template.
$localeId = 1033 # or whatever is appropriate for you
$customTemplate = $theSite.RootWeb.GetAvailableWebTemplates($localeId) | ? { $_.Title -match "Custom Template Title" }
Now, you can create a subsite based on NO template at all, and then apply the custom template:
$newSubsite = $New-SPWeb "http://server/pathto/site/subsite" # can also apply options for unique permissions, nav bar, etc.
$newSubsite.ApplyWebTemplate($customTemplate)