Import module in profile without prompt

This topic contains 4 replies, has 2 voices, and was last updated by  Jonathon Olson 3 years, 9 months ago.

  • Author
    Posts
  • #11685

    Jonathon Olson
    Participant

    Is there any way to use import-module without a prompt to load modules from a profile at PowerShell start? I don't see a -quiet switch for the cmdlet.

  • #11686

    Don Jones
    Keymaster

    It's probably your execution policy. Import-Module doesn't generate a prompt per se. But the right combination of module and execution policy can certainly generate prompts.

    What's (a) the prompt you're seeing and (b) your execution policy?

  • #11687

    Jonathon Olson
    Participant

    Ok. It is probably the particular module I am trying to load. () The line in my profile is:

    import-module dnsshell

    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 C:\Users\Jolson\Documents\WindowsPowerShell\Modules\dnsshell\DnsShell.Format.ps1xml?
    [D] Do not run [R] Run once [S] Suspend [?] Help (default is "D"):

    PS C:\Users\Jolson> Get-ExecutionPolicy
    Unrestricted

  • #11688

    Don Jones
    Keymaster

    The module is a script module, which puts it under control of your execution policy. Even under "Unrestricted," the shell prompts (by default) for scripts coming from a remote location, or scripts you downloaded from the Internet (Outlook and IE both flip a bit in the file header). Option 1, flip the bit so the file doesn't look like it came from the Internet (see http://www.howtogeek.com/70012/what-causes-the-file-downloaded-from-the-internet-warning-and-how-can-i-easily-remove-it/).

    Alternately, you can use the Bypass execution policy (see http://blogs.technet.com/b/christwe/archive/2012/09/21/but-i-ran-set-executionpolicy-unrestricted-what-is-going-on.aspx).

    See http://blogs.msdn.com/b/powershell/archive/2007/05/06/running-scripts-downloaded-from-the-internet.aspx for background information. The behavior is also documented in the Set-ExecutionPolicy cmdlet's help, I believe.

    • #11690

      Jonathon Olson
      Participant

      Thanks, removing the Zone.Identifier information allows it to load. I used the Sysinternals tool, but wondering if it could have been done in Powershell came across this Stack Overflow post:
      http://stackoverflow.com/questions/1617509/unblock-a-file-with-powershell
      There's an unblock-file cmdlet in PowerShell v3, but overwriting the stream info with cmd /c "echo.>test.exe:Zone.Identifier" would be a way to do this without leaving the shell.

You must be logged in to reply to this topic.