user829174
user829174

Reputation: 6362

Powershell, how to add permission to shared folder

I have the following code which creates a shared folder

if (!(Test-Path c:\myFolder))
{
    New-Item -Path 'c:\myFolder' -ItemType Directory
}

If (!(GET-WMIOBJECT Win32_Share -Filter "Name='myFolder'”))
{ 
    $Shares.Create(“c:\myFolder”,”myFolder”,0)
}

How can i add Read/Write permission to 'Everyone' to the shared folder? I prefer not to add external dll

Thanks

Upvotes: 3

Views: 10887

Answers (2)

Aaron Jensen
Aaron Jensen

Reputation: 26719

The Carbon module has an Install-Share function that will do what you need:

 Install-Share -Name myFolder -Path C:\myFolder -Permissions "EVERYONE,FULL"

Internally, Install-Share is using the net share console application. I believe if you run net share /?, you'll get syntax on how to create a share from the command line.

Disclaimer: I am the owner/maintainer of Carbon.

Upvotes: 2

Shay Levy
Shay Levy

Reputation: 126702

Try the Set-SharePermission function from the ShareUtils module (http://en-us.sysadmins.lv/Lists/Posts/Post.aspx?ID=28):

Import-Module ShareUtils

Get-Share -Name myFolder | 
Set-SharePermission -User Everyone -AccessType Allow -Permission Change | 
Set-Share

Upvotes: 1

Related Questions