我正在从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
设置,脚本也将运行。