Advenced sharing, share name

rated by 0 users
This post has 3 Replies | 2 Followers

Not Ranked
Posts 3
deurmat Posted: 05-04-2012 4:04 AM

Hi, I have adjusted a script I found online for adding the correct permissions to some shared folders.

Here is a part of the code I use.

# users rights for SYSTEM
$colRights = [System.Security.AccessControl.FileSystemRights]"FullControl"
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit,ObjectInherit"
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType =[System.Security.AccessControl.AccessControlType]::Allow
$objUser = New-Object System.Security.Principal.NTAccount("SYSTEM")
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule `
($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)
$objACL = Get-ACL "C:\shared\users"
$objACL.AddAccessRule($objACE)
###$objACL.SetAccessRuleProtection($True,$False)
Set-ACL "C:\shared\users" $objACL

Now this folder "users" should not be visible on the client PC's. So in advanced sharing I normaly adjust the share name to "users$".

I can't find the solution for how to do this in my script online. Does anyone here maybe have an idea?

Thx in advance!

Top 10 Contributor
Posts 640

Programmatically, you have to do this when the share is initially created - create it with the desired name. 

But this script isn't creating a share (like users$) - it's only creating, and assigning permissions, to folders. You would then normally run a command like NET SHARE to actually share the folder, and that command is where you specify the share name (like users$).

If someone is physically using the computer, they will be able to see C;\Shared\Users in Windows Explorer. Someone on the network will not see the Users$ share, though, unless they're an administrator.

Understand that there are two components here: The FOLDER and then the SHARE, which makes the folder accessible to the network. 

Not Ranked
Posts 3

Ow, I have created the shares like this:

 

$Sharename = @("C:\shared\fldredir","C:\shared\profiles","C:\shared\programs","C:\shared\shared","C:\shared\tseprofiles","C:\shared\users")

Foreach ($item in $sharename){
    New-Item $item -type Directory   
}

 

Top 10 Contributor
Posts 640

No, those aren't shares, those are directories on disk. That's different from a share ("shared folder"). 

Page 1 of 1 (4 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.