简体   繁体   中英

Quick and Dirty way to 'Unblock' ps1 files from 'System.Net.WebClient.DownloadFile'

I have a script that downloads ps1 files to run on new machine start up. I don't want to install any powershell add in or extension methods. I just want to unblock the files and run them. Any suggestions?

$scriptsourcepath = "http://myUrl/"
$scripts = "SQLSetup-Admin.ps1","SQLSetup-NonAdmin.ps1","SQLConfigure.bat"
$downloadpath = "d:\vncutil\"
$clnt = New-Object System.Net.WebClient 

foreach($script in $scripts){
    $url = $scriptsourcepath + $script
    $file = Join-Path $downloadpath $script
    $clnt.DownloadFile($url, $file)
}
$batfile = Join-Path $downloadpath "SQLConfigure.bat"
$execStr = '$batfile >>d:\vncutil\SQLConfigure.log'
& $execStr

This post from Scott Hanselman explains how the zone information is embedded in an alternate data stream, you can use that knowledge to unblock your files.

If you are able to use an external tool, the easiest way is to use streams.exe from SysInternals:

streams.exe -d yourscript.ps1

Got the answer on another forum: Not that @driis wasn't on target but this is more powershelly

http://social.technet.microsoft.com/Forums/en/winserverpowershell/thread/0b5f1fa6-981e-4696-84bc-b8046564ec8b

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