[英]Why script is executing after downloaded from internet ( azure blob ) when execution policy is set as RemoteSigned
我正在从azure blob存储下载一个脚本,然后在powershell脚本中执行。 无论我的计算机上设置了什么策略,都将下载并执行它的获取。 目前,我的计算机策略已设置为“ 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
设置,脚本也将运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.