Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update DeleteAllWebParts.ps1
  • Loading branch information
JakubPiegza authored Feb 28, 2020
commit 98936a4722605f64fcc08b19c133c07e6c2059bf
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
function Remove-SPOWebParts
{
param (
[Parameter(Mandatory=$true,Position=1)]
function Remove-SPOWebParts{
param (
[Parameter(Mandatory=$true,Position=1)]
[string]$Username,
[Parameter(Mandatory=$true,Position=2)]
[string]$Url,
[Parameter(Mandatory=$true,Position=3)]
[Parameter(Mandatory=$true,Position=3)]
$password,
[Parameter(Mandatory=$true,Position=4)]
[string]$pageUrl
)
)


$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$ctx.Load($ctx.Web)
$ctx.ExecuteQuery()
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$ctx.Load($ctx.Web)
$ctx.ExecuteQuery()

$page = $ctx.Web.GetFileByServerRelativeUrl($pageUrl)
$wpm = $page.GetLimitedWebPartManager("Shared")
$ctx.Load($wpm);
$ctx.Load($wpm.WebParts);
$ctx.ExecuteQuery()
$page = $ctx.Web.GetFileByServerRelativeUrl($pageUrl)
$wpm = $page.GetLimitedWebPartManager("Shared")
$ctx.Load($wpm);
$ctx.Load($wpm.WebParts);
$ctx.ExecuteQuery()

foreach($webbie in $wpm.WebParts)
{
foreach($webbie in $wpm.WebParts){
Write-Host "Deleting web part id: " $webbie.Id
$webbie.DeleteWebPart()

$ctx.ExecuteQuery()
}


}









}
}



Expand All @@ -56,4 +43,4 @@ $username="t@trial567.onmicrosoft.com"
$Url="https://trial567.sharepoint.com/sites/powie64"


Remove-SPOWebParts -Username $username -Url $Url -password $AdminPassword -pageUrl "/sites/powie64/SitePages/pgie.aspx"
Remove-SPOWebParts -Username $username -Url $Url -password $AdminPassword -pageUrl "/sites/powie64/SitePages/pgie.aspx"