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?