简体   繁体   中英

Why script is executing after downloaded from internet ( azure blob ) when execution policy is set as RemoteSigned

I am downloading a script from azure blob storage and executing afterwards in powershell script. its get's downloaded and executed regardless of the policy set on my machine. At the moment, my machine policy is being set as "RemoteSigned"

In code side, I configured InitialSessionState's executionPolicy property as 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();

It just executes the script

and script is

   $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

According to my knowledge of Execution policy it must never execute until and unless it contains a signed certificate or signature. But it still executes. Can any body let me know why?

Check the zone identifier with Get-Content $ScriptPath -Stream zone.identifier . If the stream doesn't exist then the script will run even with the RemoteSigned setting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM