Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

How create a drive to a network share with Powershell New-PSDrive

05 May,2018 by Tom Collins

Question: I'm trying build some Powershell scripts to automate and standardize the SQL Server patching process. One of the steps is to create a temporary drive with a dedicated letter . This drive should be mapped to a network share. That way the executable , which exists on the network , will run as if on the local server.

How can I create the new drive , mapped to a network share in Powershell?

Answer: Powershell has a few different cmdlets  for this purpose. I like using New-PSDrive . The New-PSDRive allows you to nominate a drive letter , point to a network share and persist.

This is an example of how to apply New-PSDrive . In this case , I'm creating a new drive "S" - mapped to the network share.

New-PSDrive -Name "S" -Root '"\\mmynetworkshare\data\SQL KB4058561_SQL_Server_2016_SP1_CU"' -Persist -PSProvider "FileSystem"

 

If you're interested in more Powershell scripts check Powershell scripts for DBA

 


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How create a drive to a network share with Powershell New-PSDrive


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer