다음을 통해 공유


Unblock-File

Unblocks files that were downloaded from the internet.

구문

ByPath (기본값)

Unblock-File
    [-Path] <String[]>
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

ByLiteralPath

Unblock-File
    -LiteralPath <String[]>
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

The Unblock-File cmdlet lets you open files that were downloaded from the internet. It unblocks PowerShell script files that were downloaded from the internet so you can run them, even when the PowerShell execution policy is RemoteSigned. By default, these files are blocked to protect the computer from untrusted files.

Before using the Unblock-File cmdlet, review the file and its source and verify that it is safe to open.

Internally, the Unblock-File cmdlet removes the Zone.Identifier alternate data stream, which has a value of 3 to indicate that it was downloaded from the internet.

For more information about PowerShell execution policies, see about_Execution_Policies.

This cmdlet was introduced in Windows PowerShell 3.0.

예제

Example 1: Unblock a file

This command unblocks the PowerShellTips.chm file.

PS C:\> Unblock-File -Path C:\Users\User01\Documents\Downloads\PowerShellTips.chm

Example 2: Unblock multiple files

This command unblocks all of the files in the C:\Downloads directory whose names include "PowerShell". Do not run a command like this one until you have verified that all files are safe.

PS C:\> dir C:\Downloads\*PowerShell* | Unblock-File

Example 3: Find and unblock scripts

This command shows how to find and unblock PowerShell scripts.

The first command uses the Stream parameter of the Get-Item cmdlet get files with the Zone.Identifier stream.

The second command shows what happens when you run a blocked script in a PowerShell session in which the execution policy is RemoteSigned. The RemoteSigned policy prevents you from running scripts that are downloaded from the internet unless they are digitally signed.

The third command uses the Unblock-File cmdlet to unblock the script so it can run in the session.

PS C:\> Get-Item * -Stream "Zone.Identifier" -ErrorAction SilentlyContinue
   FileName: C:\ps-test\Start-ActivityTracker.ps1

Stream                   Length
------                   ------
Zone.Identifier              26

PS C:\> C:\ps-test\Start-ActivityTracker.ps1
C:\ps-test\Start-ActivityTracker.ps1 : File C:\ps-test\Start-ActivityTracker.ps1 cannot
be loaded. The file C:\ps-test\Start-ActivityTracker.ps1 is not digitally signed. The script
will not execute on the system. For more information, see about_Execution_Policies.

At line:1 char:1
+ C:\ps-test\Start-ActivityTracker.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

PS C:\> Get-Item C:\ps-test\Start-ActivityTracker.ps1 | Unblock-File

매개 변수

-Confirm

Prompts you for confirmation before running the cmdlet.

매개 변수 속성

형식:SwitchParameter
Default value:False
와일드카드 지원:False
DontShow:False
별칭:cf

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-LiteralPath

Specifies the files to unblock. Unlike Path, the value of the LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks ('). Single quotation marks tell PowerShell not to interpret any characters as escape sequences.

매개 변수 속성

형식:

String[]

Default value:None
와일드카드 지원:False
DontShow:False
별칭:PSPath, LP

매개 변수 집합

ByLiteralPath
Position:Named
필수:True
파이프라인의 값:False
속성 이름별 파이프라인의 값:True
나머지 인수의 값:False

-Path

Specifies the files to unblock. Wildcard characters are supported.

매개 변수 속성

형식:

String[]

Default value:None
와일드카드 지원:True
DontShow:False

매개 변수 집합

ByPath
Position:0
필수:True
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

매개 변수 속성

형식:SwitchParameter
Default value:False
와일드카드 지원:False
DontShow:False
별칭:wi

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

입력

String

You can pipe a file path to this cmdlet.

출력

None

This cmdlet returns no output.

참고

  • The Unblock-File cmdlet works only in file system drives.
  • Unblock-File performs the same operation as the Unblock button on the Properties dialog box in File Explorer.
  • If you use the Unblock-File cmdlet on a file that is not blocked, the command has no effect on the unblocked file and the cmdlet does not generate errors.