Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm having trouble running a powershell script automatically. When every I call or Execute the script, I get a security prompt requesting I enter "R" to run. I have already set the execution policy to 'unrestricted' and have verified its set. Does anyone have any suggestions?

Security Warning: Run only scripts that you trust. while scripts from the Internet can be useful, the script can potentially harm your computer. Do you want to run C:\test\win7.ps1?

I am currently running the powershell script via powershell.exe call in cmd. I have also tried to run this directly from powershell and get the same error message.

powershell -command C:\nst\win7.ps1 "var1" "var2" "var3"

I have also tried running the following command via cmd:

powershell -executionpolicy unrestricted -command C:\nst\win7.ps1 "var1" "var2" "var3"

Win7 Script:

$domain = $args[0]
$pwd = $args[2]
$usr = $args[1]
$password = ConvertTo-SecureString $pwd -AsPlainText -Force
$username = "$domain\$usr"
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -DomainName $domain -Credential $credential

Any and all help would be greatly appreciated

share|improve this question
    
Just to clarify: When you say "running a powershell script automatically" what exactly does this mean? Automatically at startup via startup folder? At a specific time via scheduled task? --- Also, can't you execute PS script in general or only when using CMD first? –  nixda Sep 4 '13 at 21:57

1 Answer 1

up vote 4 down vote accepted

The problem is that the file you're trying to execute has an alternate file stream that indicates that it came from the Internet. To make the message go away, you merely need to delete the stream. Sysinternals has a free utility called streams.exe that can easily do this for you. (It is important to note, as indicated in the message, that if the file did come from the public Internet, you should be cautious when executing it and make sure you understand completely what it's going to do.)

Once you have streams.exe, the command will be:

streams.exe -d C:\nst\win7.ps1

Viewing the alternate stream from the command line can be tricky, however, notepad++ can open them. On my system, the command would be:

"c:\Program Files (x86)\Notepad++\notepad++.exe" "e:\temp\test.ps1:Zone.Identifier:$DATA"

Also, if you're curious, the stream giving you all the grief contains:

[ZoneTransfer]
ZoneId=3

Defined ZoneIds are:

Local machine = 0
Intranet      = 1
Trusted       = 2
Internet      = 3
Restricted    = 4
share|improve this answer
1  
Thank you for your help. That work perfectly. –  Mpit52 Sep 5 '13 at 17:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.