Create File Shares Remotely

Share |

Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus

13 Free SQL Tools from Idera

Free Ebook: Mastering Powershell


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

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


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 All rights reserved.