#Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version #Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Force Import-Module Microsoft.Online.SharePoint.PowerShell -Force $Cred = Get-Credential Connect-SPOService -Url "https://italsortbuttrio-admin.sharepoint.com" # ************** SUB PROJ **************** $webURL = "https://italsortbuttrio.sharepoint.com/sites/Commesse2025" #Setup credentials to connect $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) #Get Web information and subsites $Context = New-Object Microsoft.SharePoint.Client.ClientContext($webURL) $Context.Credentials = $Credentials $Web = $context.Web $Context.Load($web) $Context.Load($web.Webs) $Context.executeQuery() #Iterate through each subsite in the current web foreach ($Subweb in $web.Webs) { #Get the web object #$Subweb $SubwebURL = $Subweb.Url $SubwebTitle = $Subweb.Title write-host "Subsite URL: " $Subweb.url $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SubwebURL) $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) $LibraryName= "SottoCommesse $SubwebTitle" $Library=$Ctx.web.Lists.GetByTitle($LibraryName) $Ctx.Load($Library) $Ctx.ExecuteQuery() $viewFields = New-Object System.Collections.Specialized.StringCollection $viewFields.Add("DocIcon") > $null $viewFields.Add("LinkFilename") > $null $viewFields.Add("_ExtendedDescription") > $null $viewFields.Add("PAL_Item") > $null $viewFields.Add("PAL_ItemCode") > $null $viewFields.Add("PAL_ItemDescription") > $null $viewFields.Add("PAL_SerialNumber") > $null $viewFields.Add("Modified") > $null $viewFields.Add("Editor") > $null $viewFields.Add("Version") > $null $viewFields.Add("PAL_Status") > $null $viewInfo = New-Object Microsoft.SharePoint.Client.ViewCreationInformation $viewInfo.Paged = $true $viewInfo.SetAsDefaultView = $true $viewInfo.ViewFields = $viewFields $viewInfo.Title = "$LibraryName View" $newView = $Library.Views.Add($viewInfo) $Ctx.ExecuteQuery() $View = $Library.Views[0] $Ctx.Load($View) $Ctx.ExecuteQuery() $projNameWithoutDash = $SubwebTitle -replace "-", "" $Ctx.web.RootFolder.WelcomePage = "SottoCommesse%20" + $projNameWithoutDash + "/Forms/SottoCommesse%20" + $projNameWithoutDash + "%20View.aspx" $Ctx.web.RootFolder.Update() $Ctx.ExecuteQuery() } # ************** QUOTATIONS **************** # $SiteURL= "https://italsortbuttrio.sharepoint.com/sites/Offerte" # $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) # $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) # for ($i = 3; $i -le 5; $i++) { # $year = "202$i" # $LibraryName="Offerte $year" # $Library=$Ctx.web.Lists.GetByTitle($LibraryName) # $Ctx.Load($Library) # $Ctx.ExecuteQuery() # $viewFields = New-Object System.Collections.Specialized.StringCollection # $viewFields.Add("DocIcon") > $null # $viewFields.Add("LinkFilename") > $null # $viewFields.Add("PAL_Quotation_Reason") > $null # $viewFields.Add("PAL_ID_Quotation") > $null # $viewFields.Add("PAL_Quotation_Name") > $null # $viewFields.Add("PAL_Authors") > $null # $viewFields.Add("PAL_Status") > $null # # $viewQuery = ' # # ' + $L1Folder + '' # $viewInfo = New-Object Microsoft.SharePoint.Client.ViewCreationInformation # # $viewInfo.Query = $viewQuery # # $viewInfo.RowLimit = 50 # $viewInfo.Paged = $true # $viewInfo.SetAsDefaultView = $true # $viewInfo.ViewFields = $viewFields # $viewInfo.Title = "$LibraryName View" # $newView = $Library.Views.Add($viewInfo) # $Ctx.ExecuteQuery() # } # ************** PURCHASING PO **************** # $SiteURL= "https://italsortbuttrio.sharepoint.com/teams/purchasing/OrdinidiAcquisto/" # $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) # $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) # for ($i = 2; $i -le 5; $i++) { # $year = "202$i" # $LibraryName="Ordini di Acquisto $year" # $Library=$Ctx.web.Lists.GetByTitle($LibraryName) # $Ctx.Load($Library) # $Ctx.ExecuteQuery() # $viewFields = New-Object System.Collections.Specialized.StringCollection # $viewFields.Add("DocIcon") > $null # $viewFields.Add("LinkFilename") > $null # $viewFields.Add("PAL_PO_Supplier") > $null # $viewFields.Add("PAL_Status") > $null # $viewInfo = New-Object Microsoft.SharePoint.Client.ViewCreationInformation # $viewInfo.Paged = $true # $viewInfo.SetAsDefaultView = $true # $viewInfo.ViewFields = $viewFields # $viewInfo.Title = "$LibraryName View" # $newView = $Library.Views.Add($viewInfo) # $Ctx.ExecuteQuery() # } # ************** PURCHASING DDT **************** # $SiteURL= "https://italsortbuttrio.sharepoint.com/teams/purchasing/DDTdiAcquisto" # $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) # $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) # for ($i = 2; $i -le 5; $i++) { # $year = "202$i" # $LibraryName="DDT di Acquisto $year" # $Library=$Ctx.web.Lists.GetByTitle($LibraryName) # $Ctx.Load($Library) # $Ctx.ExecuteQuery() # $viewFields = New-Object System.Collections.Specialized.StringCollection # $viewFields.Add("DocIcon") > $null # $viewFields.Add("LinkFilename") > $null # $viewFields.Add("PAL_PO_Supplier") > $null # $viewFields.Add("PAL_Status") > $null # $viewInfo = New-Object Microsoft.SharePoint.Client.ViewCreationInformation # $viewInfo.Paged = $true # $viewInfo.SetAsDefaultView = $true # $viewInfo.ViewFields = $viewFields # $viewInfo.Title = "$LibraryName View" # $newView = $Library.Views.Add($viewInfo) # $Ctx.ExecuteQuery() # } # ************** PURCHASING RDA **************** # $SiteURL= "https://italsortbuttrio.sharepoint.com/teams/purchasing/RichiestediAcquisto" # $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) # $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) # for ($i = 2; $i -le 5; $i++) { # $year = "202$i" # $LibraryName="Richieste di Acquisto $year" # $Library=$Ctx.web.Lists.GetByTitle($LibraryName) # $Ctx.Load($Library) # $Ctx.ExecuteQuery() # $viewFields = New-Object System.Collections.Specialized.StringCollection # $viewFields.Add("DocIcon") > $null # $viewFields.Add("LinkFilename") > $null # $viewFields.Add("PAL_PO_Supplier") > $null # $viewFields.Add("PAL_Status") > $null # $viewInfo = New-Object Microsoft.SharePoint.Client.ViewCreationInformation # $viewInfo.Paged = $true # $viewInfo.SetAsDefaultView = $true # $viewInfo.ViewFields = $viewFields # $viewInfo.Title = "$LibraryName View" # $newView = $Library.Views.Add($viewInfo) # $Ctx.ExecuteQuery() # } # ************** NC but NCS**************** # $SiteURL= "https://italsortbuttrio.sharepoint.com/sites/NonConformità" # $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) # $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) # for ($i = 2; $i -le 5; $i++) { # $year = "202$i" # $LibraryName="Non Conformità $year" # $Library=$Ctx.web.Lists.GetByTitle($LibraryName) # $Ctx.Load($Library) # $Ctx.ExecuteQuery() # $viewFields = New-Object System.Collections.Specialized.StringCollection # $viewFields.Add("DocIcon") > $null # $viewFields.Add("LinkFilename") > $null # $viewFields.Add("PAL_NC_Source") > $null # $viewFields.Add("PAL_NC_Reference") > $null # $viewFields.Add("PAL_NC_Nominative") > $null # $viewFields.Add("PAL_NC_DateOfDetection") > $null # $viewFields.Add("PAL_NC_Project") > $null # $viewFields.Add("PAL_NC_ItemCode") > $null # $viewFields.Add("PAL_NC_PortalUrl") > $null # $viewFields.Add("PAL_Status") > $null # $viewInfo = New-Object Microsoft.SharePoint.Client.ViewCreationInformation # $viewInfo.Paged = $true # $viewInfo.SetAsDefaultView = $true # $viewInfo.ViewFields = $viewFields # $viewInfo.Title = "$LibraryName View" # $newView = $Library.Views.Add($viewInfo) # $Ctx.ExecuteQuery() # }