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.
ReTweet this Tip!
Jan 30 2013, 06:00 AM