SharePoint Online : manage folder permission with PowerShell - 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

Related

How can I fetch the sites or subsites from a site collection and export them to excel document?

I've been trying to fetch the subsites from a site collection and export them into excel document, and I've been checking different scripts and testing to get a special one which could help me to get this information, even though none of them have work.
I've tested these two:
https://sposcripts.com/get-all-sites-and-subsites/
https://sharepoint.stackexchange.com/questions/300136/how-can-i-get-all-site-collections-and-sub-sites-inside-a-powershell-script
enter image description here
You may need to -UseWebLogin to sign in the MFA enabled account. Try using this:
Connect-PnPOnline -Url https://contoso.sharepoint.com -UseWebLogin
OR
Connect-PnPOnline -Url https://contoso.sharepoint.com -PnPManagementShell -LaunchBrowser

Cannot export site template

I'm trying to get site template and getting error:
PS C:\Windows\system32> Get-PnPSiteTemplate -Out template.xml
Get-PnPSiteTemplate : GetAccessTokenAsync() called without an ACS token generator. Specify in AuthenticationManager constructor the authentication parameters
At line:1 char:1
Get-PnPSiteTemplate -Out template.xml
CategoryInfo : WriteError: (:) [Get-PnPSiteTemplate], ArgumentException
FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Provisioning.Site.GetSiteTemplate
Version:
pnp.powershell 1.6.0
I had the same issue and after quite some time invested in troubleshooting, I've figured out that the export gets interrupted once it iterates over a list. It is not related to the site you're trying to export because it happened also on other, newly created sites.
It turned out that the problem was that the PNP Module requires Admin Consent since it can manipulate almost all components of O365.
Solution: Connect to the site with the following command:
Connect-PnPOnline -interactive -URL "Your Site Url"
Provide admin consent to PnP and then try to export the site template with:
Get-PnPSiteTemplate -Out "File Location" # Use handlers and other params if needed
If the prompt window doesn't show up, run the following command first:
register-pnpmanagementshellaccess # See notes before running this cmdlet
Note: Admin consent requires additional permissions and SharePoint Admin role is not enough! So either ask a Global Admin to consent for you or ask for additional AD permissions. If I'm not mistaken Application Administrator role should be the right choice.
This seems to have worked for me.
Get-PnPSiteTemplate -out template.xml -ExcludeHandlers Lists,ApplicationLifecycleManagement
It seems the lists and ALM sections need an ACS token generator and that fails with UseWebLogin.
This is what I got on version 1.7.10, but I have used 1.7.0 and 1.5.0 and seen the same issues. I don't know if the older versions have more problematic modules.
Method: I found this resolution by running Set-PnPTraceLog -on -logfile log.txt -Level Debug and Set-PnPTraceLog -off, then reviewing log file to see which module failed.
I may use the Export-PnPListToSiteTemplate and see how that goes in getting list XML for the template file.
I had the same issue with PnP.PowerShell 1.6.0. I was using Connect-PnPOnline command with -UseWebLogin flag because my account had multi factor authentication turned on.
My solution was to disable MFA for my user and connect without the "-UseWebLogin" flag. Then Get-PnPSiteTemplate command worked without any issues.
I'm not sure why this is happening, but I'll use this workaround for now :)

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.

Remove SharePoint Site with Remove-PnPTenantSite in PowerShell not working

I want to Remove a SharePoint Site via PowerShell by using Remove-PnPTenantSite.
This is not working because my Site is still part of an Office 365-Group and i have to delete that first.
To delete the Office 365-Group i have to get the Unified Group.
I tried to use Get-PnPUnifiedGroup, but that throws this:
Get-PnPUnifiedGroup : Exception while invoking endpoint https://login.microsoftonline.com/TOKEN/oauth2/token.
It would already help to get one of this two Methods to work,
Thanks in advance!
I had to create an app with the Microsoft-Graph-Api permissions, connect pnp online with the app credentials, then delete the unified Group , connect with the normal credentials and then delete the site:
Connect-PnPOnline -AppId AppID -AppSecret AppSecret -AADDomain Domain
Connect-PnPOnline -Url $siteUrl -Credentials $cred
Remove-PnPUnifiedGroup -Identity Title
Remove-PnPTenantSite Url -Force

Powershell: Grant-NfsSharePermission Full Permissions

Powershell v3.0 Windows Server 2012
I am trying to use the Grant-NfsSharePermission cmdlet to grant read/write access to all users with local admins having full permissions to a NFS share.
Grant-NfsSharePermission -Name "LABS" -Path "C:\LABS" -ClientName "WIN-TGE0C741D5G" -ClientType "builtin" -Permission readwrite
The error I get is the parameter set cannot be resolved using the specified name parameters. It's in the InvalidArgument category. After looking at the built-in examples, I can't seem to see why this is a problem. I even tried replacing the clientname (which is my machine name) with localhost and 127.0.0.1 and same error.
The Grant-NfsSharePermission cmdlet expects either the name of the NFS share or the path to the share. You provided both and it doesn't like that. Provide either just -Name or just -Path, but not both and it should work.
As TheMadTechnician mentioned in the comments, you can see this by reviewing the online help or built-in help (with Get-Help Grant-NfsSharePermission) and seeing they provide two parameter sets and the examples only show the use of one or the other.