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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added optional `-Connection` parameter to `Get-PnPConnection`, `Get-PnPContext` and `Set-PnPContext` which allows for using any of these for a specific connection [#1919](https://github.com/pnp/powershell/pull/1919)
- Added `-IncludeDeprecated` parameter to `Get-PnPTerm` cmdlet to fetch deprecated terms if specified [#1903](https://github.com/pnp/powershell/pull/1903)
- Added optional `-ValidateConnection` to `Connect-PnPOnline` which will check if the site you are connecting to exists and if not, will throw an exception [#1924](https://github.com/pnp/powershell/pull/1924)
- Added `Add-PnPListItemAttachment` cmdlet to provide ability to upload a file as an attachment to a SharePoint list item. [#1932](https://github.com/pnp/powershell/pull/1932)
- Added `Remove-PnPListItemAttachment` cmdlet to provide ability to delete a list item attachment. [#1932](https://github.com/pnp/powershell/pull/1932)
- Added `Get-PnPListItemAttachment` cmdlet to download the attachments from a list item. [#1932](https://github.com/pnp/powershell/pull/1932)

### Changed
- Changed `Sync-PnPSharePointUserProfilesFromAzureActiveDirectory` to map users based on their Ids instead which should resolve some issues around user identities reporting not to exist. You can use the new `-IdType` option to switch it back to `PrincipalName` if needed. [#1752](https://github.com/pnp/powershell/pull/1752)
Expand Down
176 changes: 176 additions & 0 deletions documentation/Add-PnPListItemAttachment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Add-PnPListItemAttachment.html
external help file: PnP.PowerShell.dll-Help.xml
title: Add-PnPListItemAttachment
---

# Add-PnPListItemAttachment

## SYNOPSIS
Adds an attachment to the specified list item in the SharePoint list

## SYNTAX

### Upload attachment file from path
```powershell
Add-PnPListItemAttachment [-List] <ListPipeBind> [-Identity] <ListItemPipeBind> [-Path <String>] [-NewFileName <String>] [-Connection <PnPConnection>] [<CommonParameters>]
```

### Upload attachment file from stream
```powershell
Add-PnPListItemAttachment [-List] <ListPipeBind> [-Identity] <ListItemPipeBind> [-FileName <String>] [-Stream <Stream>] [-Connection <PnPConnection>] [<CommonParameters>]
```

### Create attachment file from text
```powershell
Add-PnPListItemAttachment [-List] <ListPipeBind> [-Identity] <ListItemPipeBind> [-FileName <String>] [-Content <text>] [-Connection <PnPConnection>] [<CommonParameters>]
```

## DESCRIPTION

This cmdlet allows adding a file as an attachment to a list item in a SharePoint Online list.

## EXAMPLES

### EXAMPLE 1
```powershell
Add-PnPListItemAttachement -List "Demo List" -Identity 1 -Path c:\temp\test.mp4
```

Adds a new attachment to the list item with Id "1" in the "Demo List" SharePoint list with file name as test.mp4 from the specified path.


### EXAMPLE 2
```powershell
Add-PnPListItemAttachement -List "Demo List" -Identity 1 -FileName "test.txt" -Content '{ "Test": "Value" }'
```

Adds a new attachment to the list item with Id "1" in the "Demo List" SharePoint list with file name as test.txt and content as specified.

### EXAMPLE 3
```powershell
Add-PnPListItemAttachement -List "Demo List" -Identity 1 -FileName "test.mp4" -Stream $fileStream
```

Adds a new attachment to the list item with Id "1" in the "Demo List" SharePoint list with file name as test.mp4 and content coming from a stream.

## PARAMETERS

### -Content
Specify text of the attachment for the list item.

```yaml
Type: String
Parameter Sets: (Upload file from text)

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

### -Path
The local file path

```yaml
Type: String
Parameter Sets: (Upload file)

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

### -NewFileName
Filename to give to the attachment file on SharePoint

```yaml
Type: String
Parameter Sets: (Upload file)

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

### -FileName
Filename to give to the attachment file on SharePoint

```yaml
Type: String
Parameter Sets: (Upload file from stream, Upload file from text)

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

### -Stream
Stream with the file contents

```yaml
Type: Stream
Parameter Sets: (Upload file from stream)

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

### -List
The ID, Title or Url of the list. Note that when providing the name of the list, the name is case-sensitive.

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

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -Identity
The ID of the listitem, or actual ListItem object to add the attachment to.

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

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

### -Connection
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.

```yaml
Type: PnPConnection
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)
114 changes: 114 additions & 0 deletions documentation/Get-PnPListItemAttachments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPListItemAttachment.html
external help file: PnP.PowerShell.dll-Help.xml
title: Get-PnPListItemAttachment
---

# Get-PnPListItemAttachment

## SYNOPSIS
Downloads the list item attachments to a specified path on the file system.

## SYNTAX

### Get attachments from list item
```powershell
Get-PnPListItemAttachment [-List] <ListPipeBind> [-Identity] <ListItemPipeBind> [-Path <String>] [-Force <SwitchParameter>] [-Connection <PnPConnection>] [<CommonParameters>]
```

## DESCRIPTION

## EXAMPLES

### EXAMPLE 1
```powershell
Get-PnPListItemAttachment -List "Demo List" -Identity 1 -Path "C:\temp"
```

Downloads all attachments from the list item with Id "1" in the "Demo List" SharePoint list and stores them in the temp folder.

### EXAMPLE 2
```powershell
Get-PnPListItemAttachment -List "Demo List" -Identity 1 -Path "C:\temp" -Force
```

Downloads all attachments from the list item with Id "1" in the "Demo List" SharePoint list and stores them in the temp folder overwriting the files if they already exist.

## PARAMETERS

### -Path
Specify the path on the local file system to download the list item attachments to.

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

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

### -List
The ID, Title or Url of the list. Note that when providing the name of the list, the name is case-sensitive.

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

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -Identity
The ID of the listitem, or actual ListItem object

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

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

### -Force
Specifying the Force parameter will skip the confirmation question and overwrite the files on the local disk, if they already exist.

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

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

### -Connection
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.

```yaml
Type: PnPConnection
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)
Loading