Skip to content

Commit 4ed7441

Browse files
authored
Merge pull request #4785 from KoenZomers/Issue4752
Fixes `Get-PnPSiteScriptFromWeb` throwing a file not found error when providing a web URL through `-Url` that differs from the connected to URL
2 parents 6c29d4f + f836827 commit 4ed7441

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
114114
- Fixed `Get-PnPChangeLog` not returning the changelog [#4707](https://github.com/pnp/powershell/pull/4707)
115115
- Fixed `-Description` and `-Sequence` not being applied when providing these through `Add-PnPApplicationCustomizer` [#4767](https://github.com/pnp/powershell/pull/4767)
116116
- Fixed `-RetryCount` parameter being ignored with `Submit-PnPSearchQuery` [#4784](https://github.com/pnp/powershell/pull/4784)
117+
- Fixed `Get-PnPSiteScriptFromWeb` throwing a file not found error when providing a web URL through `-Url` that differed from the connected to URL [#4785](https://github.com/pnp/powershell/pull/4785)
117118

118119
### Removed
119120

src/Commands/SiteDesigns/GetSiteScriptFromWeb.cs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,40 @@ public class GetSiteScriptFromWeb : PnPSharePointOnlineAdminCmdlet
1515
private const string ParameterSet_ALLLISTS = "All lists";
1616
private const string ParameterSet_SPECIFICCOMPONENTS = "Specific components";
1717

18-
[Parameter(ParameterSetName = ParameterSet_BASICCOMPONENTS)]
19-
[Parameter(ParameterSetName = ParameterSet_ALLCOMPONENTS)]
20-
[Parameter(ParameterSetName = ParameterSet_ALLLISTS)]
21-
[Parameter(ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
22-
[Parameter(Mandatory = false, ValueFromPipeline = true)]
18+
[Parameter(Mandatory = false, ValueFromPipeline = true, ParameterSetName = ParameterSet_BASICCOMPONENTS)]
19+
[Parameter(Mandatory = false, ValueFromPipeline = true, ParameterSetName = ParameterSet_ALLCOMPONENTS)]
20+
[Parameter(Mandatory = false, ValueFromPipeline = true, ParameterSetName = ParameterSet_ALLLISTS)]
21+
[Parameter(Mandatory = false, ValueFromPipeline = true, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
2322
public string Url;
2423

25-
[Parameter(ParameterSetName = ParameterSet_BASICCOMPONENTS)]
26-
[Parameter(ParameterSetName = ParameterSet_ALLCOMPONENTS)]
27-
[Parameter(ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
28-
[Parameter(Mandatory = false)]
24+
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_BASICCOMPONENTS)]
25+
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALLCOMPONENTS)]
26+
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
2927
public string[] Lists;
3028

3129
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALLCOMPONENTS)]
3230
public SwitchParameter IncludeAll;
3331

34-
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALLLISTS)]
35-
public SwitchParameter IncludeAllLists;
32+
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_ALLLISTS)]
33+
public SwitchParameter IncludeAllLists;
3634

37-
[Parameter(ParameterSetName = ParameterSet_ALLLISTS)]
35+
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALLLISTS)]
3836
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
3937
public SwitchParameter IncludeBranding;
4038

41-
[Parameter(ParameterSetName = ParameterSet_ALLLISTS)]
39+
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALLLISTS)]
4240
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
4341
public SwitchParameter IncludeLinksToExportedItems;
4442

45-
[Parameter(ParameterSetName = ParameterSet_ALLLISTS)]
43+
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALLLISTS)]
4644
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
4745
public SwitchParameter IncludeRegionalSettings;
4846

49-
[Parameter(ParameterSetName = ParameterSet_ALLLISTS)]
47+
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALLLISTS)]
5048
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
5149
public SwitchParameter IncludeSiteExternalSharingCapability;
5250

53-
[Parameter(ParameterSetName = ParameterSet_ALLLISTS)]
51+
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALLLISTS)]
5452
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFICCOMPONENTS)]
5553
public SwitchParameter IncludeTheme;
5654

@@ -61,13 +59,23 @@ protected override void ExecuteCmdlet()
6159
{
6260
Url = Connection.Url;
6361
}
62+
63+
WriteVerbose($"Creating site script from web {Url}");
6464

65-
if(IncludeAllLists || IncludeAll)
65+
if (IncludeAllLists || IncludeAll)
6666
{
67-
ClientContext.Load(ClientContext.Web.Lists, lists => lists.Where(list => !list.Hidden && !list.IsCatalog && !list.IsSystemList && !list.IsPrivate && !list.IsApplicationList && !list.IsSiteAssetsLibrary && !list.IsEnterpriseGalleryLibrary).Include(list => list.RootFolder.ServerRelativeUrl));
68-
ClientContext.ExecuteQueryRetry();
67+
var targetWebContext = Url != Connection.Url ? Connection.CloneContext(Url) : ClientContext;
68+
69+
targetWebContext.Load(targetWebContext.Web.Lists, lists => lists.Where(list => !list.Hidden && !list.IsCatalog && !list.IsSystemList && !list.IsPrivate && !list.IsApplicationList && !list.IsSiteAssetsLibrary && !list.IsEnterpriseGalleryLibrary).Include(list => list.RootFolder.ServerRelativeUrl));
70+
targetWebContext.ExecuteQueryRetry();
71+
72+
Lists = targetWebContext.Web.Lists.Select(l => System.Text.RegularExpressions.Regex.Replace(l.RootFolder.ServerRelativeUrl, @"\/(?:sites|teams)\/.*?\/", string.Empty)).ToArray();
6973

70-
Lists = ClientContext.Web.Lists.Select(l => System.Text.RegularExpressions.Regex.Replace(l.RootFolder.ServerRelativeUrl, @"\/(?:sites|teams)\/.*?\/", string.Empty)).ToArray();
74+
WriteVerbose($"Including all custom lists and libraries in the site script... {Lists.Length} found");
75+
foreach (var list in Lists)
76+
{
77+
WriteVerbose($"- {list}");
78+
}
7179
}
7280

7381
var tenantSiteScriptSerializationInfo = new TenantSiteScriptSerializationInfo

0 commit comments

Comments
 (0)