Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Net use with a variable

$
0
0

Hi,

I am trying to fetch a path from a database and map a drive to that path with the code below:

$ArchivePath = Invoke-Sqlcmd -query "SELECT [value] FROM [MyDB].[dbo].[PartitioningConfiguration] (nolock) WHERE name = 'ArchivePath'"


If (!(Test-Path A:)) {net use A: $ArchivePath[0]}

The first command works fine and populates $ArchivePath variable with a correct value.

The second command fails with the following error:

"The network name can not be found"

I can confirm that the path exists and accessible.  The net use command works if I just hardcode the value into the command, but does not work with a variable.

Any ideas?

Thanks.

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles