After that I want to change the directory to be the newly created drive. What I am doing:
cd $drive:
$someEnv = $drive + ":\include"
Changing the directory is not working. And I guess the second line too.
Can you please help me how I can change the directory successfully based on the network drive name and then in$someEnv store for example if the network drive is X:
Don’t you get errors? New-PSDrive does not have a parameter -Path. You have to provide a value for the parameter -Root. Please read the complete help to learn how to use it. And you sould not use ENV as a variable name as it is a reserved Powershell variable - About Environment Variables. And as you already have only one drive in your variable $drive you should not use ($drive)[0] as this cuts off the colon from your drive name.
Sorry, my mistake. That’s actually right like you did it. But because your variable $drive already includes the colon your following commands should cause errors actually.
Why don’t you use the same syntax you used to create the mapped drive?
BTW:
When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to you help making their work twice or more.
I agree, even though the context of the two posts is different. The original post here is about the changing the directory and you helped a lot. I didn’t had much time that’s why I didn’t referenced this one on the stackoverwflow.