Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command runs in ISE but not as ps1 in Console

Tags:

powershell

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

New-PSDrive –Name "G" –PSProvider FileSystem –Root "\\dom\dfs\dom-loc-Share" –Persist

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?

like image 401
Asharon Avatar asked Sep 27 '22 04:09

Asharon


1 Answers

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. [...]

New-PSDrive –Name "G" –PSProvider FileSystem –Root "\\dom\dfs\dom-loc-Share" –Persist -Scope Global
like image 94
hdev Avatar answered Nov 15 '22 03:11

hdev