Create File Shares Remotely

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

To create a new file share remotely, you could use the WMI class Win32_Share and its Create() method. Invoke-WmiMethod helps you run WMI methods locally and remotely. To create a new share locally or remotely, try this:

$Path = 'C:\'
$Name = 'serviceshare'
$Type = 0
$Maximumallowed = 5
$Description = 'PowerShell Share'
$ComputerName = 'storage1'
$rv = Invoke-WmiMethod -Path 'Win32_Share' -ComputerName $ComputerName -Name Create -ArgumentList $null, $Description, $MaximumAllowed, $Name, $null, $Path, $Type
$rv.ReturnValue 

This would create a new share called "serviceshare" on the machine "storage1". Remove the parameter -ComputerName if you want to run the method locally on your machine. Add the parameter -Credential if you want to run the command remotely with a different identity.

Twitter This Tip! ReTweet this Tip!


Posted Jan 30 2013, 06:00 AM by ps1

Comments

Shane1357 wrote re: Create File Shares Remotely
on 01-30-2013 12:50 PM

I must be doing something wrong. I followed your steps posted and run into no errors it seems.  Nothing, however, is created.  I've even tried this locally by leaving out the -ComputerName and still no share is created.  Suggestions?

Copyright 2012 PowerShell.com. All rights reserved.