Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit c892448

Browse files
Merge pull request #1726 from erwinvanhunen/dev
Added Get-PnPException cmdlet
2 parents f8d0cbb + 324b921 commit c892448

8 files changed

+203
-29
lines changed

CHANGELOG.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
77

88
## [3.2.1810.0] Unreleased
99
### Added
10-
- Add-PnPProvisioningSequence
11-
- Add-PnPProvisioningSite
12-
- Add-PnPProvisioningSubSite
13-
- Apply-PnPProvisioningHierarchy
14-
- Get-PnPProvisioningSite
15-
- New-PnPProvisioningHierarchy
16-
- New-PnPProvisioningSequence
17-
- New-PnPProvisioningCommunicationSite
18-
- New-PnPProvisioningTeamNoGroupSite
19-
- New-PnPProvisioningTeamNoGroupSubSite
20-
- New-PnPProvisioningTeamSite
21-
- Read-PnPProvisioningHierarchy
22-
- Save-PnPProvisioningHierarchy
23-
- Test-PnPProvisioningHierarchy
10+
- Add-PnPProvisioningSequence : Adds an in-memory sequence to an in-memory provisioning hierarchy
11+
- Add-PnPProvisioningSite : Adds an in-memory site definition to a in-memory sequence
12+
- Add-PnPProvisioningSubSite : Adds an in-memory sub site defintion to an in-memory site
13+
- Apply-PnPProvisioningHierarchy : Applies a provisioninghierarchy with a site sequence to a tenant
14+
- Get-PnPProvisioningSite : Returns a site as an in-memory object from a given provisioning hierarchy
15+
- New-PnPProvisioningHierarchy : Creates a new in-memory provisioning hierarchy
16+
- New-PnPProvisioningSequence : Creates a new in-memory provisioning sequence
17+
- New-PnPProvisioningCommunicationSite : Creates a new in-memory communication site definition
18+
- New-PnPProvisioningTeamNoGroupSite : Creates a new in-memory team site definition which has no associated office365 group
19+
- New-PnPProvisioningTeamNoGroupSubSite : Creates a new in-memory team sub site definition which has no associated office365 group
20+
- New-PnPProvisioningTeamSite : Creates a new in-memory team site definition
21+
- Read-PnPProvisioningHierarchy : Reads an existing (file based) provisioning hierarchy into an in-memory instance
22+
- Save-PnPProvisioningHierarchy : Saves an in-memory provisioning hierarchy to a pnp file
23+
- Test-PnPProvisioningHierarchy : Tests an in-memory hierarchy if all template references are correct in the site sequence
24+
- Get-PnPException : Returns the last occured exception that occured while using PowerShell.
2425

2526
### Changed
2627
- Updated Set-PnPSite to allow for setting of a logo on modern team site

Commands/Base/GetException.cs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using SharePointPnP.PowerShell.CmdletHelpAttributes;
2+
using SharePointPnP.PowerShell.Commands.Model;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.Management.Automation;
6+
7+
namespace SharePointPnP.PowerShell.Commands.Base
8+
{
9+
[Cmdlet(VerbsCommon.Get, "PnPException")]
10+
[CmdletHelp("Returns the last exception that occured",
11+
@"Returns the last exception which can be used while debugging PnP Cmdlets",
12+
Category = CmdletHelpCategory.Base)]
13+
[CmdletExample(
14+
Code = @"PS:> Get-PnPException",
15+
Remarks = "Returns the last exception",
16+
SortOrder = 1)]
17+
[CmdletExample(
18+
Code = @"PS:> Get-PnPException -All",
19+
Remarks = "Returns all exceptions that occurred",
20+
SortOrder = 2)]
21+
public class GetException : PSCmdlet
22+
{
23+
[Parameter(Mandatory = false, HelpMessage = "Show all exceptions")]
24+
public SwitchParameter All;
25+
26+
protected override void ProcessRecord()
27+
{
28+
var exceptions = (ArrayList)this.SessionState.PSVariable.Get("error").Value;
29+
if (exceptions.Count > 0)
30+
{
31+
var output = new List<PnPException>();
32+
if (All.IsPresent)
33+
{
34+
foreach (ErrorRecord exception in exceptions)
35+
{
36+
output.Add(new PnPException() { Message = exception.Exception.Message, Stacktrace = exception.Exception.StackTrace, ScriptLineNumber = exception.InvocationInfo.ScriptLineNumber, InvocationInfo = exception.InvocationInfo });
37+
}
38+
}
39+
else
40+
{
41+
var exception = (ErrorRecord)exceptions[0];
42+
output.Add(new PnPException() { Message = exception.Exception.Message, Stacktrace = exception.Exception.StackTrace, ScriptLineNumber = exception.InvocationInfo.ScriptLineNumber, InvocationInfo = exception.InvocationInfo });
43+
}
44+
WriteObject(output, true);
45+
}
46+
}
47+
}
48+
}

Commands/Model/PnPException.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Management.Automation;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace SharePointPnP.PowerShell.Commands.Model
9+
{
10+
public class PnPException
11+
{
12+
public string Message;
13+
public string Stacktrace;
14+
public int ScriptLineNumber;
15+
public InvocationInfo InvocationInfo;
16+
}
17+
}

Commands/ModuleFiles/SharePointPnP.PowerShell.2013.Commands.Format.ps1xml

+23
Original file line numberDiff line numberDiff line change
@@ -1306,5 +1306,28 @@
13061306
</TableRowEntries>
13071307
</TableControl>
13081308
</View>
1309+
<View>
1310+
<Name>PnPException</Name>
1311+
<ViewSelectedBy>
1312+
<TypeName>SharePointPnP.PowerShell.Commands.Model.PnPException</TypeName>
1313+
</ViewSelectedBy>
1314+
<ListControl>
1315+
<ListEntries>
1316+
<ListEntry>
1317+
<ListItems>
1318+
<ListItem>
1319+
<PropertyName>Message</PropertyName>
1320+
</ListItem>
1321+
<ListItem>
1322+
<PropertyName>Stacktrace</PropertyName>
1323+
</ListItem>
1324+
<ListItem>
1325+
<PropertyName>ScriptLineNumber</PropertyName>
1326+
</ListItem>
1327+
</ListItems>
1328+
</ListEntry>
1329+
</ListEntries>
1330+
</ListControl>
1331+
</View>
13091332
</ViewDefinitions>
13101333
</Configuration>

Commands/ModuleFiles/SharePointPnP.PowerShell.2016.Commands.Format.ps1xml

+23
Original file line numberDiff line numberDiff line change
@@ -1306,5 +1306,28 @@
13061306
</TableRowEntries>
13071307
</TableControl>
13081308
</View>
1309+
<View>
1310+
<Name>PnPException</Name>
1311+
<ViewSelectedBy>
1312+
<TypeName>SharePointPnP.PowerShell.Commands.Model.PnPException</TypeName>
1313+
</ViewSelectedBy>
1314+
<ListControl>
1315+
<ListEntries>
1316+
<ListEntry>
1317+
<ListItems>
1318+
<ListItem>
1319+
<PropertyName>Message</PropertyName>
1320+
</ListItem>
1321+
<ListItem>
1322+
<PropertyName>Stacktrace</PropertyName>
1323+
</ListItem>
1324+
<ListItem>
1325+
<PropertyName>ScriptLineNumber</PropertyName>
1326+
</ListItem>
1327+
</ListItems>
1328+
</ListEntry>
1329+
</ListEntries>
1330+
</ListControl>
1331+
</View>
13091332
</ViewDefinitions>
13101333
</Configuration>

Commands/ModuleFiles/SharePointPnP.PowerShell.Core.Format.ps1xml

+50-13
Original file line numberDiff line numberDiff line change
@@ -589,30 +589,30 @@
589589
<TableColumnItem>
590590
<ScriptBlock>
591591
if($_.Name -eq ""){
592-
$_.ServerRelativeUrl.TrimEnd("/").Substring($_.ServerRelativeUrl.TrimEnd("/").LastIndexOf("/") + 1)
592+
$_.ServerRelativeUrl.TrimEnd("/").Substring($_.ServerRelativeUrl.TrimEnd("/").LastIndexOf("/") + 1)
593593
}
594594
else{
595-
$_.Name
595+
$_.Name
596596
}
597597
</ScriptBlock>
598598
</TableColumnItem>
599599
<TableColumnItem>
600600
<ScriptBlock>
601601
if($_.GetType().Name -eq "Folder" -and $_.Name -eq ""){
602-
"Subweb"
602+
"Subweb"
603603
}
604604
else{
605-
$_.GetType().Name
605+
$_.GetType().Name
606606
}
607607
</ScriptBlock>
608608
</TableColumnItem>
609609
<TableColumnItem>
610610
<ScriptBlock>
611611
if($_.GetType().Name -eq "File"){
612-
$_.Length
612+
$_.Length
613613
}
614614
else{
615-
$_.ItemCount
615+
$_.ItemCount
616616
}
617617
</ScriptBlock>
618618
</TableColumnItem>
@@ -801,6 +801,9 @@
801801
<Width>36</Width>
802802
<Alignment>left</Alignment>
803803
</TableColumnHeader>
804+
<TableColumnHeader>
805+
<Label>Child Terms</Label>
806+
</TableColumnHeader>
804807
</TableHeaders>
805808
<TableRowEntries>
806809
<TableRowEntry>
@@ -811,6 +814,16 @@
811814
<TableColumnItem>
812815
<PropertyName>Id</PropertyName>
813816
</TableColumnItem>
817+
<TableColumnItem>
818+
<ScriptBlock>
819+
if($_.IsObjectPropertyInstantiated("Terms")){
820+
$_.TermsCount
821+
}
822+
else{
823+
"$($_.TermsCount) (Not loaded)"
824+
}
825+
</ScriptBlock>
826+
</TableColumnItem>
814827
</TableColumnItems>
815828
</TableRowEntry>
816829
</TableRowEntries>
@@ -1290,7 +1303,7 @@
12901303
<TableColumnHeader>
12911304
<Label>Alias</Label>
12921305
<Alignment>left</Alignment>
1293-
</TableColumnHeader>
1306+
</TableColumnHeader>
12941307
</TableHeaders>
12951308
<TableRowEntries>
12961309
<TableRowEntry>
@@ -1366,7 +1379,8 @@
13661379
</TableRowEntry>
13671380
</TableRowEntries>
13681381
</TableControl>
1369-
</View><View>
1382+
</View>
1383+
<View>
13701384
<Name>TenantSiteDesign</Name>
13711385
<ViewSelectedBy>
13721386
<TypeName>Microsoft.Online.SharePoint.TenantAdministration.TenantSiteDesign</TypeName>
@@ -1439,7 +1453,7 @@
14391453
<TableColumnItem>
14401454
<PropertyName>Version</PropertyName>
14411455
</TableColumnItem>
1442-
<TableColumnItem>
1456+
<TableColumnItem>
14431457
<PropertyName>Content</PropertyName>
14441458
</TableColumnItem>
14451459
</TableColumnItems>
@@ -1515,7 +1529,7 @@
15151529
<Label>Position</Label>
15161530
<Alignment>left</Alignment>
15171531
</TableColumnHeader>
1518-
<TableColumnHeader>
1532+
<TableColumnHeader>
15191533
<Label>PropertiesJson</Label>
15201534
<Alignment>left</Alignment>
15211535
</TableColumnHeader>
@@ -1541,20 +1555,20 @@
15411555
<TableColumnItem>
15421556
<PropertyName>Order</PropertyName>
15431557
</TableColumnItem>
1544-
<TableColumnItem>
1558+
<TableColumnItem>
15451559
<PropertyName>PropertiesJson</PropertyName>
15461560
</TableColumnItem>
15471561
</TableColumnItems>
15481562
</TableRowEntry>
15491563
</TableRowEntries>
15501564
</TableControl>
15511565
</View>
1552-
<View>
1566+
<View>
15531567
<Name>NavigationNode</Name>
15541568
<ViewSelectedBy>
15551569
<TypeName>Microsoft.SharePoint.Client.NavigationNode</TypeName>
15561570
</ViewSelectedBy>
1557-
<TableControl>
1571+
<TableControl>
15581572
<TableHeaders>
15591573
<TableColumnHeader>
15601574
<Label>Id</Label>
@@ -1780,5 +1794,28 @@
17801794
</TableRowEntries>
17811795
</TableControl>
17821796
</View>
1797+
<View>
1798+
<Name>PnPException</Name>
1799+
<ViewSelectedBy>
1800+
<TypeName>SharePointPnP.PowerShell.Commands.Model.PnPException</TypeName>
1801+
</ViewSelectedBy>
1802+
<ListControl>
1803+
<ListEntries>
1804+
<ListEntry>
1805+
<ListItems>
1806+
<ListItem>
1807+
<PropertyName>Message</PropertyName>
1808+
</ListItem>
1809+
<ListItem>
1810+
<PropertyName>Stacktrace</PropertyName>
1811+
</ListItem>
1812+
<ListItem>
1813+
<PropertyName>ScriptLineNumber</PropertyName>
1814+
</ListItem>
1815+
</ListItems>
1816+
</ListEntry>
1817+
</ListEntries>
1818+
</ListControl>
1819+
</View>
17831820
</ViewDefinitions>
17841821
</Configuration>

Commands/ModuleFiles/SharePointPnP.PowerShell.Online.Commands.Format.ps1xml

+25-2
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,10 @@
811811
<TableColumnItem>
812812
<ScriptBlock>
813813
if($_.IsObjectPropertyInstantiated("Terms")){
814-
$_.TermsCount
814+
$_.TermsCount
815815
}
816816
else{
817-
"$($_.TermsCount) (Not loaded)"
817+
"$($_.TermsCount) (Not loaded)"
818818
}
819819
</ScriptBlock>
820820
</TableColumnItem>
@@ -1846,5 +1846,28 @@
18461846
</TableRowEntries>
18471847
</TableControl>
18481848
</View>
1849+
<View>
1850+
<Name>PnPException</Name>
1851+
<ViewSelectedBy>
1852+
<TypeName>SharePointPnP.PowerShell.Commands.Model.PnPException</TypeName>
1853+
</ViewSelectedBy>
1854+
<ListControl>
1855+
<ListEntries>
1856+
<ListEntry>
1857+
<ListItems>
1858+
<ListItem>
1859+
<PropertyName>Message</PropertyName>
1860+
</ListItem>
1861+
<ListItem>
1862+
<PropertyName>Stacktrace</PropertyName>
1863+
</ListItem>
1864+
<ListItem>
1865+
<PropertyName>ScriptLineNumber</PropertyName>
1866+
</ListItem>
1867+
</ListItems>
1868+
</ListEntry>
1869+
</ListEntries>
1870+
</ListControl>
1871+
</View>
18491872
</ViewDefinitions>
18501873
</Configuration>

Commands/SharePointPnP.PowerShell.Commands.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@
459459
<Compile Include="Admin\RemoveTenantTheme.cs" />
460460
<Compile Include="Base\AddStoredCredential.cs" />
461461
<Compile Include="Base\DisablePowerShellTelemetry.cs" />
462+
<Compile Include="Base\GetException.cs" />
462463
<Compile Include="Base\GetPowerShellTelemetryEnabled.cs" />
463464
<Compile Include="Base\EnablePowerShellTelemetry.cs" />
464465
<Compile Include="Base\GetAccessToken.cs" />
@@ -480,6 +481,7 @@
480481
<Compile Include="Enums\StorageEntityScope.cs" />
481482
<Compile Include="InformationManagement\GetLabel.cs" />
482483
<Compile Include="InformationManagement\SetLabel.cs" />
484+
<Compile Include="Model\PnPException.cs" />
483485
<Compile Include="Model\ServicePrincipalPermissionGrant.cs" />
484486
<Compile Include="Navigation\GetNavigationNode.cs" />
485487
<Compile Include="Branding\SetWebTheme.cs" />

0 commit comments

Comments
 (0)