I'm trying to map a network drive in a script by two ways but any of them don't work
One is
#New-PSDrive -Name "Z" -PSProvider FileSystem -Root '\\server\share' -Persist
It doesn't show any error but it doesn't appear in the windows explorer
The other way is
$net = $(New-Object -ComObject wscript.Network)
$net.mapnetworkdrive('z:', $path)
This shows me the next error
Exception calling "MapNetworkDrive" with "2" argument(s): "Object reference not set to an instance of an object.
Thanks
Mapping a network drive
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- SAPIEN Support Forums
- Posts: 945
- Last visit: Thu Oct 22, 2015 1:10 pm
Mapping a network drive
This is an automated post. A real person will respond soon.
Thank you for posting, jramon.r@tv3.cat.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
Anticipate follow-up questions!
Did you remember to include the following?
*** Make sure you do not post any licensing information ***
Thank you for posting, jramon.r@tv3.cat.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
- - Scripting question? For questions about Windows PowerShell or other scripting languages, use Scripting Answers.
- Software question? For questions about PowerShell Studio, PrimalScript, or other SAPIEN products, use Product Support Forums for Registered Customers.
- Trial question? For questions about trial versions of any SAPIEN product, use Trial Software Questions.
Anticipate follow-up questions!
Did you remember to include the following?
- 1. Product, version and build
2. 32 or 64 bit product
3. Operating system, e.g. Windows 7 64 bit.
4. Attach a screenshot, if applicable
5. Attach logs, crash reports, etc., in a ZIP file
*** Make sure you do not post any licensing information ***
Re: Mapping a network drive
YOu forgot to remove the comment tag '#'
New-PSDrive -Name Z -PSProvider FileSystem -Root '\\server\share' -Persist
No need to quote drive name in this case.
Don't forget to change \\server\share to your names.
New-PSDrive -Name Z -PSProvider FileSystem -Root '\\server\share' -Persist
No need to quote drive name in this case.
Don't forget to change \\server\share to your names.
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am
Re: Mapping a network drive
#jvierra wrote:YOu forgot to remove the comment tag '#'
New-PSDrive -Name Z -PSProvider FileSystem -Root '\\server\share' -Persist
No need to quote drive name in this case.
Don't forget to change \\server\share to your names.
- jramon.r@tv3.cat
- Posts: 25
- Last visit: Tue Jan 11, 2022 4:23 am
Re: Mapping a network drive
I've removed the tag # and the "" to the letter but it stills doesn't work.
If I run this in the PowerShell ISE it works ok but if I run this in PowerShell Studio doesn't appear the letter in the windows explorer.
What is happening?
Thank you
If I run this in the PowerShell ISE it works ok but if I run this in PowerShell Studio doesn't appear the letter in the windows explorer.
What is happening?
Thank you
- jramon.r@tv3.cat
- Posts: 25
- Last visit: Tue Jan 11, 2022 4:23 am
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Mapping a network drive
That is the PowerShell Studio version and not the selected PowerShell version. Regardless, you did not specify your OS or version as asked in the auto-response post, but I am assuming Windows 7 or above.
So in that case mapping drives requires elevation.
The ISE runs elevated by default (I will not comment on that practice) but PowerShell Studio does not.
Run your script elevated, there is a button on the ribbon to turn that on.
So in that case mapping drives requires elevation.
The ISE runs elevated by default (I will not comment on that practice) but PowerShell Studio does not.
Run your script elevated, there is a button on the ribbon to turn that on.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- jramon.r@tv3.cat
- Posts: 25
- Last visit: Tue Jan 11, 2022 4:23 am
Re: Mapping a network drive
The version of PowerShell is 4.0 and the O.S is Windows 2008, it's a server.
I've already executed the script elevated.
Thanks
I've already executed the script elevated.
Thanks
Re: Mapping a network drive
Mapping drives does not require elevation. Even lowly users can map a drive. Proof is that we do it all of the time in logon scripts.
Group Policy can affect this.
In Vista days there was a bug that would not allow a newly mapped drive to be visible between an elevated and a normal session.
Windows 2008 is now out of support so I have no systems to test on. Try searching for information on this bug. I seem to remember that there was a registry hack to override this behavior.
This is not really a scripting issue. It is more of a system issue.
Group Policy can affect this.
In Vista days there was a bug that would not allow a newly mapped drive to be visible between an elevated and a normal session.
Windows 2008 is now out of support so I have no systems to test on. Try searching for information on this bug. I seem to remember that there was a registry hack to override this behavior.
This is not really a scripting issue. It is more of a system issue.