Get-PnPFile

Tip

We encourage you to make improvements to this documentation. Please navigate to https://github.com/pnp/powershell/blob/dev/documentation/Get-PnPFile.md to change this file.

Downloads a file.

Syntax

Get-PnPFile
   [-Url] <String>
   -AsFileObject
   [-Connection <PnPConnection>]
   [<CommonParameters>]
Get-PnPFile
   [-Url] <String>
   -AsListItem
   [-ThrowExceptionIfFileNotFound]
    [-Connection <PnPConnection>]
   [<CommonParameters>]
Get-PnPFile
   [-Url] <String>
   -AsFile
   [-Path <String>]
   [-Filename <String>]
   [-Force]
    [-Connection <PnPConnection>]
   [<CommonParameters>]
Get-PnPFile
   [-Url] <String>
   -AsString
   [-Connection <PnPConnection>]
   [<CommonParameters>]

Examples

EXAMPLE 1

Get-PnPFile -Url /sites/project/_catalogs/themes/15/company.spcolor

Retrieves the file and downloads it to the current folder

EXAMPLE 2

Get-PnPFile -Url /sites/project/_catalogs/themes/15/company.spcolor -Path c:\temp -FileName company.spcolor -AsFile

Retrieves the file and downloads it to c:\temp\company.spcolor

EXAMPLE 3

Get-PnPFile -Url /sites/project/_catalogs/themes/15/company.spcolor -AsString

Retrieves the file and outputs its contents to the console

EXAMPLE 4

Get-PnPFile -Url /sites/project/_catalogs/themes/15/company.spcolor -AsFile

Retrieves the file and returns it as a File object

EXAMPLE 5

Get-PnPFile -Url /sites/project/_catalogs/themes/15/company.spcolor -AsListItem

Retrieves the file and returns it as a ListItem object

EXAMPLE 6

Get-PnPFile -Url _catalogs/themes/15/company.spcolor -Path c:\temp -FileName company.spcolor -AsFile

Retrieves the file by site relative URL and downloads it to c:\temp\company.spcolor

Parameters

-AsFile
Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-AsFileObject

Retrieve the file contents as a file object.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-AsListItem

Returns the file as a listitem showing all its properties

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-AsString

Retrieve the file contents as a string

Type:SwitchParameter
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.

Type:PnPConnection
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Filename

Name for the local file

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Force

Overwrites the file if it exists.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Path

Local path where the file should be saved

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ThrowExceptionIfFileNotFound

If provided in combination with -AsListItem, a System.ArgumentException will be thrown if the file specified in the -Url argument does not exist. Otherwise it will return nothing instead.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Url

The URL (server or site relative) to the file

Type:String
Aliases:ServerRelativeUrl, SiteRelativeUrl
Position:0
Default value:None
Accept pipeline input:True
Accept wildcard characters:False