Unblock-File not unblocking file

Hello!

Working hard to learn Powershell and could use some help.

Trying to set up a Powershell FTP Client I found here:

Module is in the right place (as far as I know)

[blockquote]%USERPROFILE%\Documents\WindowsPowerShell\Modules
%WINDIR%\System32\WindowsPowerShell\v1.0\Modules[/blockquote]

I run the Cmdlet

[blockquote]Import-Module -name “PSFTP”[/blockquote]

And get this error

[blockquote]Import-Module : Errors occurred while loading the format data file:
C:\Users\Dell T7400\Documents\WindowsPowerShell\Modules\PSFTP\PSFTP.Format.ps1xml, , C:\Users\Dell
T7400\Documents\WindowsPowerShell\Modules\PSFTP\PSFTP.Format.ps1xml: The file was skipped because of the following validation
exception: File C:\Users\Dell T7400\Documents\WindowsPowerShell\Modules\PSFTP\PSFTP.Format.ps1xml cannot be loaded. The file
C:\Users\Dell T7400\Documents\WindowsPowerShell\Modules\PSFTP\PSFTP.Format.ps1xml is not digitally signed. You cannot run this script
on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at
about Execution Policies - PowerShell | Microsoft Learn…[/blockquote]

I read the Execution Policies page here

That says to run Unblock-File if my Execution Policy is RemoteSigned, which it is.

[blockquote]Unblock-File -Path “C:\Users\Dell T7400\Documents\WindowsPowerShell\Modules\PSFTP\PSFTP.Format.ps1xml”[/blockquote]

I run this without error

But when I run the same Import-Module Cmdlet I still get the same error.

[blockquote]Import-Module : Errors occurred while loading the format data file:
C:\Users\Dell T7400\Documents\WindowsPowerShell\Modules\PSFTP\PSFTP.Format.ps1xml, , C:\Users\Dell
T7400\Documents\WindowsPowerShell\Modules\PSFTP\PSFTP.Format.ps1xml: The file was skipped because of the following validation
exception: File C:\Users\Dell T7400\Documents\WindowsPowerShell\Modules\PSFTP\PSFTP.Format.ps1xml cannot be loaded. The file
C:\Users\Dell T7400\Documents\WindowsPowerShell\Modules\PSFTP\PSFTP.Format.ps1xml is not digitally signed. You cannot run this script
on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at
about Execution Policies - PowerShell | Microsoft Learn…[/blockquote]

Any ideas?

Thanks!

Are you using PowerShell 3.0 or later? If so, you can quickly tell whether that file is still blocked by running this command:

Get-Content -Path 'C:\Users\Dell T7400\Documents\WindowsPowerShell\Modules\PSFTP\PSFTP.Format.ps1xml' -Stream Zone.Identifier

If you get an error that says it couldn’t open the alternate data stream Zone.Identifier, then the file is not blocked. If it says:

[ZoneTransfer]
ZoneId=3

then the file is, indeed, still blocked for some reason. You could try this command to unblock it, though this should be doing exactly the same thing as Unblock-File, and may fail for the same reason (whatever that reason happens to be):

Remove-Item -Path 'C:\Users\Dell T7400\Documents\WindowsPowerShell\Modules\PSFTP\PSFTP.Format.ps1xml' -Stream Zone.Identifier

Thanks for your response!

I ran the first command and got the “couldn’t open the alternate…” response to it’s apparently not blocked. But when I try and use a cmdlet that the module author specifies like “Set-FTPConnection” I get the error:

“The term ‘Set-FTPConnection’ is not recognized as the name of a cmdlet”

Thanks for you help!

I’ve found the same issue while preparing for a PowerShell demo

it really looks like PowerShell is caching the info.

When I try to run a file, get the ‘digitally signed’ error, then unblock the file.
Still I cannot immediately run the unblocked file.

The file IS unblocked.
If I start a new powershell shell, the file can run…
it looks as if the first failed run is cached in the powershell session, would like to know how to clear that.

till then, the workaround is : start a new shell

Apparently that happens when we download zip (compressed) files containing several files. We would run Unblock-File against one of those (usually the .ps1), but when that references other files (and other .ps1) the same error shows up.

Quick solution is to unblock the zip file after downloading it and only then uncompress it. The uncompressed files will all be unblocked.