iamuser
asked on
How to run powershell scripts in Sharepoint Online
How do I run a Powershell command/script that calls a javascript file (stored in a folder within the main site). The powershell command/script should only apply to 1 specific site collection.
in particular, I found this script online but I can't make out how to run it:
in particular, I found this script online but I can't make out how to run it:
Write-Host "Upload RemoveGearIcon.js"
$f = Add-PnPFile -Path .\RemoveGearIcon.js -Folder "scripts"
$site = Get-PnPSite
$fileUrl = $site.Url + "/Scripts/RemoveGearIcon.js"
Write-Host "Add JavaScript Link"
$jsLink = Get-PnPJavaScriptLink -Name "RemoveGearIcon" -Scope Site
if ($jsLink -ne $null)
{
Remove-PnPJavaScriptLink -Identity "RemoveGearIcon" -Scope Site -Force
}
$link = Add-PnPJavaScriptLink -Name "RemoveGearIcon" -Url $fileUrl -Sequence 200 -Scope Site
ASKER
The powershell command was supposed to add a javascript link which it would call another script (within the site library) that would perform a specific action based on the user rights in sharepoint.
Sorry for the delayed response... (life intrudes!) In any case, the powershell command is intended to ADD a link or just CALL a script? Adding a new item via PowerShell is harder than calling.
ASKER
it was supposed to call a script. I have the script uploaded to a folder called "scripts". I think the way it was supposed to work was that this, the powershell command would add a javascript link which would load and then call and execute a script.
I have a script that will hide the gear icon if you do not have full management rights. It works fine when i add this to a webpart but this does not carry over to other pages or to the document library. In order for it to apply to everything I have to apply the script throughout the site. So the way I understand this was to have powershell create a javascript link which is then applied to the site. So each time any page is loaded, the javascript link will call the script and check if the user has full management rights, if no, then the gear icon is hidden.
I have a script that will hide the gear icon if you do not have full management rights. It works fine when i add this to a webpart but this does not carry over to other pages or to the document library. In order for it to apply to everything I have to apply the script throughout the site. So the way I understand this was to have powershell create a javascript link which is then applied to the site. So each time any page is loaded, the javascript link will call the script and check if the user has full management rights, if no, then the gear icon is hidden.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
$user = "myusername"
$pass = "super-strong-alpha-numeri
$pair = "${user}:${pass}"
$bytes = [System.Text.Encoding]::AS
$base64 = [System.Convert]::ToBase64
$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }
Invoke-WebRequest -uri "https://site.sharepoint.com/site/library/bla.js" -Headers $headers