Command runs in ISE but not as ps1 in Console

Question:

I found numerous threads and went through them but none of them really adressed my issue. I try to keep it short.

It works perfectly fine if I run it from the ISE.
It works fine when I copy paste it to the console.
It does not work if I try running the ps1 in the console.

  • I restarted the ISE
  • I checked and both run in Single Threaded Apartment
  • Executionpolicy is unrestricted
  • I run both as administrator

Can you please help me?

Answer:

Use -Scope Global, for more information visit this technet article:

about_Scopes https://technet.microsoft.com/en-us/library/hh847849.aspx

[…]
Windows PowerShell protects access to variables, aliases, functions,
and Windows PowerShell drives (PSDrives) by limiting where they can be
read and changed. By enforcing a few simple rules for scope, Windows
PowerShell helps to ensure that you do not inadvertently change an
item that should not be changed. […]

Source:

Command runs in ISE but not as ps1 in Console by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply