Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Removed support for PowerShell 5, only PowerShell 7.2 and later will be supported from here onwards [#2764](https://github.com/pnp/powershell/pull/2764)
- Removed `Get-PnPSubscribeSharePointNewsDigest` and `Set-PnPSubscribeSharePointNewsDigest` as the implementation behind these features has been changed in SharePoint Online causing them no longer to work. At present, there's no alternative for this that we can call into thus we will have to remove these in a future version. There is a Design Change Request open with the Program Group to add back APIs for doing this. If that will be accepted and implemented, we will add these back again. [#2720](https://github.com/pnp/powershell/pull/2720)
-
- Removed `-ReturnTyped` parameter from the `Get-PnPField` cmdlet. The retrieved fields will always be returned by their `TypeKind`. [#2849](https://github.com/pnp/powershell/pull/2849)

### Fixed

- Fixed issue with -CreateDrive on `Connect-PnPOnline` throwing exception on non-existing context
Expand Down
1 change: 1 addition & 0 deletions MIGRATE-1.0-to-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Using PnP PowerShell in Azure functions ? You might be required to change the Pn
| Add-PnPTeamsChannel | Private | ChannelType | The parameter was obsolete and hence removed. Use `-ChannelType` instead |
| New-PnPTeamsTeam | Owner | Owners | The parameter was obsolete and hence removed. Use `-Owners` instead which supports setting multiple owner of a Teams team |
| Export-PnPTaxonomy | - | - | The cmdlet does not support export of taxonomy using `UTF-7` encoding. If `UTF-7` is specified, it will switch to `UTF-8` encoding |
| Get-PnPField | ReturnTyped | - | The cmdlet will always return the typed object of the field. |
| Get-PnPUserProfileProperty | - | - | Additional user profile properties are no longer returned under UserProfileProperties but instead will be directly under the returned instance |

## Other notable changes
Expand Down
26 changes: 1 addition & 25 deletions documentation/Get-PnPField.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Returns a field from a list or site
## SYNTAX

```powershell
Get-PnPField [-List <ListPipeBind>] [[-Identity] <FieldPipeBind>] [-Group <String>] [-InSiteHierarchy] [-ReturnTyped]
Get-PnPField [-List <ListPipeBind>] [[-Identity] <FieldPipeBind>] [-Group <String>] [-InSiteHierarchy]
[-Connection <PnPConnection>] [-Includes <String[]>] [<CommonParameters>]
```

Expand Down Expand Up @@ -48,14 +48,6 @@ Get-PnPField -Group "Custom Columns"

Gets all the fields for the group called Custom Columns for the site currently connected to

### EXAMPLE 4

```powershell
Get-PnPField -List "Demo list" -Identity "Speakers" -ReturnTyped
```

Gets the speakers field from the list Demo list and returns it as a typed field. So, if the field type is User, it will be returned as FieldUser.

## PARAMETERS

### -Connection
Expand Down Expand Up @@ -133,22 +125,6 @@ Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -ReturnTyped

Returns the field as the specific field type instead of the generic field type when used with List parameter.
For example, if the field type is User, it will be returned as FieldUser instead of generic Field type.

```yaml
Type: SwitchParameter
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
155 changes: 73 additions & 82 deletions src/Commands/Fields/GetField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public class GetField : PnPWebRetrievalsCmdlet<Field>
[Parameter(Mandatory = false, ValueFromPipeline = false)]
public SwitchParameter InSiteHierarchy;

[Parameter(Mandatory = false, ValueFromPipeline = false)]
public SwitchParameter ReturnTyped;

protected override void ExecuteCmdlet()
{
if (List != null)
Expand Down Expand Up @@ -56,90 +53,84 @@ protected override void ExecuteCmdlet()
ClientContext.Load(field, RetrievalExpressions);
ClientContext.ExecuteQueryRetry();

if (ReturnTyped.IsPresent)
switch (field.FieldTypeKind)
{
switch (field.FieldTypeKind)
{
case FieldType.DateTime:
{
WriteObject(ClientContext.CastTo<FieldDateTime>(field));
break;
}
case FieldType.Choice:
{
WriteObject(ClientContext.CastTo<FieldChoice>(field));
break;
}
case FieldType.Calculated:
{
WriteObject(ClientContext.CastTo<FieldCalculated>(field));
break;
}
case FieldType.Computed:
{
WriteObject(ClientContext.CastTo<FieldComputed>(field));
break;
}
case FieldType.Geolocation:
{
WriteObject(ClientContext.CastTo<FieldGeolocation>(field));
break;
}
case FieldType.User:
{
WriteObject(ClientContext.CastTo<FieldUser>(field));
break;
}
case FieldType.Currency:
{
WriteObject(ClientContext.CastTo<FieldCurrency>(field));
break;
}
case FieldType.Guid:
{
WriteObject(ClientContext.CastTo<FieldGuid>(field));
break;
}
case FieldType.URL:
{
WriteObject(ClientContext.CastTo<FieldUrl>(field));
break;
}
case FieldType.Lookup:
{
WriteObject(ClientContext.CastTo<FieldLookup>(field));
break;
}
case FieldType.MultiChoice:
{
WriteObject(ClientContext.CastTo<FieldMultiChoice>(field));
break;
}
case FieldType.Number:
{
WriteObject(ClientContext.CastTo<FieldNumber>(field));
break;
}
case FieldType.Invalid:
{
if (field.TypeAsString.StartsWith("TaxonomyFieldType"))
{
WriteObject(ClientContext.CastTo<TaxonomyField>(field));
break;
}
goto default;
}
default:
case FieldType.DateTime:
{
WriteObject(ClientContext.CastTo<FieldDateTime>(field));
break;
}
case FieldType.Choice:
{
WriteObject(ClientContext.CastTo<FieldChoice>(field));
break;
}
case FieldType.Calculated:
{
WriteObject(ClientContext.CastTo<FieldCalculated>(field));
break;
}
case FieldType.Computed:
{
WriteObject(ClientContext.CastTo<FieldComputed>(field));
break;
}
case FieldType.Geolocation:
{
WriteObject(ClientContext.CastTo<FieldGeolocation>(field));
break;
}
case FieldType.User:
{
WriteObject(ClientContext.CastTo<FieldUser>(field));
break;
}
case FieldType.Currency:
{
WriteObject(ClientContext.CastTo<FieldCurrency>(field));
break;
}
case FieldType.Guid:
{
WriteObject(ClientContext.CastTo<FieldGuid>(field));
break;
}
case FieldType.URL:
{
WriteObject(ClientContext.CastTo<FieldUrl>(field));
break;
}
case FieldType.Lookup:
{
WriteObject(ClientContext.CastTo<FieldLookup>(field));
break;
}
case FieldType.MultiChoice:
{
WriteObject(ClientContext.CastTo<FieldMultiChoice>(field));
break;
}
case FieldType.Number:
{
WriteObject(ClientContext.CastTo<FieldNumber>(field));
break;
}
case FieldType.Invalid:
{
if (field.TypeAsString.StartsWith("TaxonomyFieldType"))
{
WriteObject(field);
WriteObject(ClientContext.CastTo<TaxonomyField>(field));
break;
}
}
}
else
{
WriteObject(field);
goto default;
}
default:
{
WriteObject(field);
break;
}
}

}
else if (fieldCollection != null)
{
Expand Down