Google

2011-06-22

Running PowerShell from NAS without Prompts

It's been more than a year since I bought my QNAP TS-439 Pro NAS. Slowly I moved away from storing files locally and nowadays I store everything in there, backing up nightly to a Drobo box via front USB Interface.

Today, I wrote a powershell script that was only a couple of lines long to dump Docsis Diagnosis Info of my Modem (See DocsDiag). It simply prints verbose info on a file that has date + time stamp.

$cmd = "java -cp docsdiag.jar docsdiag -vv"
$zaman=get-date -uformat "%Y.%M.%d_%H.%M"
$dosya="modem.diags_" + $zaman + ".txt"
Invoke-Command -ScriptBlock { invoke-expression $cmd } |out-file $dosya

I stored the file in my "HomeShare" which I map from my NAS. When I ran the script I got the familiar Execution Policy warning that you would see if you download a script file from internet, "OR", if you run the script from a network location.

Security Warning
Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your computer. Do you want to run Z:\scripts\powershell\cable\get-ModemInfo.ps1?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is "D"):

If you're doing this at your office, and your devs need to run scripts from Network Location, then you would probably use GPO to set Execution Level for these scripts and use Internet Explorer GPO settings to define your network (possibly using your domain name as in *.foobar.com) as Local Intranet.

For a home user like me, however, without a domain but with network storage, solution is to make changes manually:
  1. Set Execution Policy to either RemoteSigned (recommended) or Unrestricted. For this, launch PowerShell as admin (right click start as Admin) and type

    Set-ExecutionPolicy RemoteSigned or Set-ExecutionPolicy Unrestricted

    I know some people may not feel easy about setting scripts to Unrestricted but I write my own scripts, do not download from Internet and run them. As long as I am on the terminal, I can bypass this check anyway.

  2. I defined my NAS in "Local Intranet" in Internet Explorer Zone Settings. I have several mappings from my NAS, and use both IP address and an alias when mapping drives, so I added both:
    In IE, Tools > Internet Options > Security > Local Intranet > Sites, Clicked Advanced and
  • added file ://qnap (qnap is an alias in my c:\Windows\System32\Drivers\Etc\Hosts file for my NAS IP)
  • added 192.168.1.10 (IP address of NAS)
This did the trick. I no longer get the prompt. Funny thing is that Cablevision came by today replacing my old Cable Modem which was running Docsis 1.1 with one that's running Docsis 3.0. An then I found out that I can no longer query my modem using DocsDiag utility because apparently ISPs are now blocking SNMP.

Update [07/02/2011]
What a difference switching to Docsis 3.0 modem did! Speed test is rarely reporting under 14Mbit/s even on busy evening hours. 
Post a Comment