Import module in profile without prompt

Welcome Forums General PowerShell Q&A Import module in profile without prompt

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
5 years, 5 months ago.

  • Author
    Posts
  • #11685

    Participant
    Topics: 3
    Replies: 10
    Points: 24
    Rank: Member

    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

    Keymaster
    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

    Participant
    Topics: 3
    Replies: 10
    Points: 24
    Rank: Member

    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 Suspend [?] Help (default is "D"):

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

  • #11688

    Keymaster
    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

      Participant
      Topics: 3
      Replies: 10
      Points: 24
      Rank: Member

      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.

The topic ‘Import module in profile without prompt’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort