Get-PnPFile

Downloads a file.

Syntax

Get-PnPFile
   -Url <String>
              [-Web <WebPipeBind>]
              [-Connection <SPOnlineConnection>]
Get-PnPFile
   -Url <String>
              [-AsListItem [<SwitchParameter>]]
              [-ThrowExceptionIfFileNotFound [<SwitchParameter>]]
              [-Web <WebPipeBind>]
              [-Connection <SPOnlineConnection>]
Get-PnPFile
   -Url <String>
              [-AsString [<SwitchParameter>]]
              [-Web <WebPipeBind>]
              [-Connection <SPOnlineConnection>]
Get-PnPFile
   -Url <String>
              -AsFile [<SwitchParameter>]
              [-Path <String>]
              [-Filename <String>]
              [-Force [<SwitchParameter>]]
              [-Web <WebPipeBind>]
              [-Connection <SPOnlineConnection>]

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
Accept pipeline input:False
Accept wildcard characters:False
-AsListItem

Returns the file as a listitem showing all its properties

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

Retrieve the file contents as a string

Type:SwitchParameter
Position:Named
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:SPOnlineConnection
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Filename

Name for the local file

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

Overwrites the file if it exists.

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

Local path where the file should be saved

Type:String
Position:Named
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
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
Accept pipeline input:True
Accept wildcard characters:False
-Web

This parameter allows you to optionally apply the cmdlet action to a subweb within the current web. In most situations this parameter is not required and you can connect to the subweb using Connect-PnPOnline instead. Specify the GUID, server relative url (i.e. /sites/team1) or web instance of the web to apply the command to. Omit this parameter to use the current web.

Type:WebPipeBind
Position:Named
Accept pipeline input:False
Accept wildcard characters:False

Outputs

Microsoft.SharePoint.Client.File