0

I'm trying to get a script running that maps network drives at login. Generally, I use get-content with | convertfrom-stringdata to put my parameters (drive letter and path) in a hash.

My problem is the following:

net use /persistent:no $driveletter $networkpath

results with an error. When I replace $networkpath with the actual path (\\server\share\folder), it works.

Does anyone know what to do there? Help is greatly appreciated. If any information is missing, I'll add it as soon as I can!

Greetings,

Blaargh

EDIT: more code for better understanding of problem

$hash = get-content C:\temp\file.txt | convertfrom-stringdata
    foreach ($keys in $hash.keys) {
    $hashtwo = $hash.$keys -split ("=")
    net use /persistent:no $hashtwo[1] $hashtwo[0]
}

My textfile looks like this: key = \\\\server\\share\\folder =G:

briantist
  • 45,546
  • 6
  • 82
  • 127
blaargh
  • 33
  • 1
  • 10
  • Don't really see a problem with it on the surface. Are you sure `$networkpath` contains what you think it does? Does it contain spaces? If you `echo "~$networkpath~"` what do you get? – briantist Dec 17 '15 at 20:55
  • `$driveletter = "x:" `$networkpath = "\\server\share"` `net use /persistent:no $driveletter $networkpath` works fine for me as well – Avshalom Dec 17 '15 at 20:58
  • Unfortunately it doesn't work like that. Are the quotes neccessary? Let me put in some more code here to get you an idea of where the problem could be. – blaargh Dec 17 '15 at 21:03
  • When echoing $networkpath or $driveletter, it always comes up with the right content by the way – blaargh Dec 17 '15 at 21:11
  • 1
    @blaargh Add `Write-Host "'$($hashtwo[1])' '$($hashtwo[0])'"` to be sure, that variables does not have extra space somewhere. – user4003407 Dec 17 '15 at 21:17
  • @PetSerAl HUGE thanks to you. There was a space behind the path, removing it made the problem disappear. I owe you mate! – blaargh Dec 17 '15 at 21:22
  • I copied your answer and gave you the credit, I'm new on this board and hope I did it right. If not, please tell me how to correctly mark your comment as an answer. Thanks. :) – blaargh Dec 17 '15 at 21:30
  • @blaargh I does not really care much about abstract internet points, feel free to just accept your own answer. – user4003407 Dec 17 '15 at 22:12

1 Answers1

0

PetSerAl found the solution:

@blaargh Add Write-Host "'$($hashtwo[1])' '$($hashtwo[0])'" to be sure, that variables does not have extra space somewhere.

blaargh
  • 33
  • 1
  • 10