Sharepoint Check-In Document using Powershell - powershell

Does anyone know why the Set-PnPFileCheckedIn cmdlet below does nothing when executed? The file doesn't get checked in. I'm logging in with the same user that has the file checked out.
I'm not even seeing an error message. The script just runs through.
$SiteUrl = "https://orgsite.com/sites/TestSite"
$fileRelativePath = "/sites/TestSite/Documents/File.pdf"
Connect-PnPOnline -Url $SiteUrl -UseWebLogin
Set-PnPFileCheckedIn -Url $fileRelativePath

Per my test, this works for me.
Please make sure the relative url of the file is right, I assume the fileRelativePath shuold be "/sites/TestSite/Shared Documents/File.pdf".

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

Invoke-WebRequest not working through OneDrive

I have a document residing on OneDrive. The permissions are that anyone with the link can view/edit.
I have written a very short script to download the file and place it onto my desktop. However, once the file is downloaded, I open it to be greeted with a message saying that it is unreadable/corrupt. This happens with every file type I test including .ZIP folders. Here is my code:
Invoke-WebRequest -Uri "https://longobscureonedrivelink/personal/sharefile_removedforsecurity/Documents/folder/folder2/testy.pdfdownload=1" -OutFile "C:\Users\Billy\Desktop\testy.pdf"
My thinking is that it's an authentication issue but seeing as anyone with the link can view/edit I'm not sure.
I have tried adding -Credential Get-Credential and imputing the actual Microsoft account who owns the OneDrive's username and password but still no luck.
Any help is greatly appreciated.

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

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

Sharepoint online copy file script

I am having trouble copying a file within a sharepoint online list using powershell. Error I am getting is
Exception calling "ExecuteQuery" with "0" argument(s): "Server relative urls must start with SPWeb.ServerRelativeUrl"
The path is correct as i can combine context.url with the path variables and access the file using that path. I used similar paths except with getfolderbyrelativeurl to set permissions on folders with no issues (same list).
Here is the code.
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$SourceFile =$context.Web.GetFileByServerRelativeUrl("/$ListName/$sa_man_checklist")
$Context.Load($SourceFile)
$Context.ExecuteQuery()
I am very new sharepoint online and any help is much appreciated
Found the cause, not sure how anything before this worked. Server relative url should have started after host name rather than what i specified in context. Odd thing is when i called folder by server relative path taking url specified in context it still works just fine but when i try to call a file using that same method it breaks...