为什么当执行策略设置为RemoteSigned时,脚本在从internet下载后执行(azure blob)



我正在从azure blob存储中下载一个脚本,然后在powershell脚本中执行。不管我的机器上设置了什么策略,它的get都会被下载并执行。目前,我的机器策略被设置为"RemoteSigned">

在代码端,我将InitialSessionState的executionPolicy属性配置为RemoteSigned。

var iss = InitialSessionState.CreateDefault();
iss.ExecutionPolicy = ExecutionPolicy.RemoteSigned;
var runSpace = RunspaceFactory.CreateRunspace(iss);
runSpace.Open();    
PowerShellInstance = PowerShell.Create();               
PowerShellInstance.Runspace = runSpace; 
var output = PowerShellInstance.Invoke();

它只是执行脚本

脚本是

$Urls = @()
$Urls += "https://.............ps1"
$OutPath = "C:Temp"
ForEach ( $item in $Urls) {
$file = $OutPath +  ($item).split('/')[-1]
(New-Object System.Net.WebClient).DownloadFile($item, $file)
}
cd "C:Temp"
..ps1

根据我对执行策略的了解,在包含签名证书或签名之前,它永远不能执行。但它仍然执行。有人能告诉我为什么吗?

使用Get-Content $ScriptPath -Stream zone.identifier检查区域标识符。如果流不存在,则即使使用RemoteSigned设置,脚本也将运行。

最新更新