Jump to content

Recommended Posts

Posted

Hi All,

 

I've recently moved from Server 2003 to Server 2012R2...

 

On my 2003 Server I use to run a script that would Share all the folders inside a given root folder and give a Share Permission of Everybody - Full Control, NTFS Permissions were then setup on the folder using NTFSFix -

 

If I try running the same script on Server 2012R2 - It shares the folders, but only gives a Share Permission of "Read Only" - I read that the default on Server 2012R2 is Read Only - I've modified some Registry Entries to default this back to Full Control - which works great when I manually created a shared folder, but still when I run the script for a whole load of folders it sets them as Read Only.

 

Does anybody know why, or has any alternative scripts to achieve this on Server 2012r2 (Ideally that disables the offline caching of files too)

 

Here's the content of the VBS script I'm using:-

 

const MaxConnections = 0

set objFSO = createobject("Scripting.FileSystemObject")

RootFolder = inputbox("Please enter the root folder that contains the folders you want to share:")

'***** Perform some basic validation *****
if not objFSO.FolderExists(RootFolder) then
wscript.echo "Invalid Folder"
wscript.quit
end if
if mid(RootFolder,1,2)="\\" then
wscript.echo "UNC Paths are not supported"
wscript.quit
end if

set objRootFolder = objFSO.GetFolder(rootfolder)
for each fldr in objRootFolder.SubFolders
sharefolder fldr.path, fldr.name
next

wscript.echo "Completed"

sub shareFolder(byval folderPath,shareName)
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")

objNewShare.Create folderpath, shareName, MaxConnections
end sub

 

Thanks

 

Matt

  • 1 month later...
Posted

Anybody?!? Will very soon be needing to do this with setting up the new intake and the script I've used for Years on 2003 Server doesn't work on 2012R2...

 

Thanks in anticipation!

 

Matt

Posted

You could have a play with net share

 

 

PS C:\WINDOWS\system32> net share /help

The syntax of this command is:

 

 

NET SHARE

sharename

sharename=drive:path [/GRANT:user,[READ | CHANGE | FULL]]

[/uSERS:number | /UNLIMITED]

[/REMARK:"text"]

[/CACHE:Manual | Documents| Programs | BranchCache | None]

sharename [/uSERS:number | /UNLIMITED]

[/REMARK:"text"]

[/CACHE:Manual | Documents | Programs | BranchCache | None]

{sharename | devicename | drive:path} /DELETE

sharename \\computername /DELETE

 

 

NET SHARE makes a server's resources available to network users. When

used without options, it lists information about all resources being

shared on the computer. For each resource, Windows reports the

devicename(s) or pathname(s) and a descriptive comment associated with it.

 

 

sharename Is the network name of the shared resource. Type

NET SHARE with a sharename only to display information

about that share.

drive:path Specifies the absolute path of the directory to

be shared.

/GRANT:user,perm Creates the share with a security descriptor that gives

the requested permissions to the specified user. This

option may be used more than once to give share permissions

to multiple users.

/USERS:number Sets the maximum number of users who can

simultaneously access the shared resource.

/UNLIMITED Specifies an unlimited number of users can

simultaneously access the shared resource

/REMARK:"text" Adds a descriptive comment about the resource.

Enclose the text in quotation marks.

devicename Is one or more printers (LPT1: through LPT9:)

shared by sharename.

/DELETE Stops sharing the resource.

/CACHE:Manual Enables manual client caching of programs and documents

from this share

/CACHE:Documents Enables automatic caching of documents from this share

/CACHE:Programs Enables automatic caching of documents and programs

from this share

/CACHE:BranchCache Manual caching of documents with BranchCache enabled

from this share

/CACHE:None Disables caching from this share

 

 

NET HELP command | MORE displays Help one screen at a time.

Posted
You could have a play with net share

 

To use powershell it would be something like:

 

$dirs = (Get-ChildItem -Path "E:\Folders\Root" | ?{ $_.PSIsContainer })

 

foreach($dir in $dirs)

{

$sharename = $dir.fullname

net share sharename=$sharename /GRANT:Everyone,FULL /CACHE:None

}

 

 

 

I haven't tested the code above but it would be something like that

  • Thanks 1
Posted

Thanks James,

 

I've just tested the PowerShell Script (Changed the Path) and run as administrator but it doesn't seem to be working... can you spot anything obvious that maybe stopping it from running? I'm not getting any error messages when it's run, but when I check the folders that I've tested it on none of them appear to be shared and permissions set?

 

Thanks again!

 

Matt

Posted

Silly question, but why do you want each individual folder shared out for new intakes? If this is their home area aren't you just sharing the "home area" folder, and letting permissions inherit down etc?

 

Steve

Posted

I guess from old habits -

 

So each home drive doesn't need to be "shared" to allow it to be mapped as a home drive for each user?

 

Our Structure is setup like this...

 

Home

- Year 07

- Year 08

- Year 09

- Year 10

- Year 11

- Year 12

- Year 13

- Teaching

- Support

 

If I continued with that format - would I need to share each Root folder or just the home folder - currently we map the drives to \\SERVERNAME\SHARE\%username% - I assume that wouldn't work under our current structure and would need to map each year group to the root folder? \\SERVERNAME\SHARE\YEARGROUP\%username%

 

Thanks

 

Matt

Posted

As long as one of parent folders for the users areas is shared, you can just use the long UNC path in AD for the home share location.

 

We have just moved all our students from \\SERVERNAME\%USERNAME%$ to \\SERVERNAME\STUDENTS$\YOE\%USERNAME% as it saves having hundreds of shares, and if we need to move the users to another drive we just have to recreate 1 share

Posted

I've seen it done both ways, don't think either is better as such but as the others have said its a little easier on admin to use a global "homes" share

 

I've just tested the script, try this:

 

 

$dirs = (Get-ChildItem -Path "D:\Jen and James\Documents\test\path" | ?{ $_.PSIsContainer })

 

foreach($dir in $dirs)

{

$sharename = $dir.name

$path = $dir.fullname

 

 

net share $sharename="$path" /GRANT:Everyone,FULL /CACHE:None

}

 

 

  • Thanks 1
Posted (edited)
I've just tested the script, try this:

Btw, on Server 2012/2012 R2 you could use the New-SmbShare PowerShell cmdlet instead of the old Net Share. :)

 

#Requires -Modules SmbShare

$dirs = Get-ChildItem -Path "D:\Test" -Directory

ForEach($dir in $dirs)
{
   New-SmbShare -Name $dir.Name -Path $dir.FullName -FullAccess Everyone -CachingMode None -FolderEnumerationMode AccessBased -ErrorAction SilentlyContinue
}

Edited by Arthur
  • Thanks 1
Posted

Thanks guys...

 

The script is working perfectly now...

 

Following previous replies to this post - I'm just trying to work out the pro's and con's to setting up each home drive as a shared or just the root.

 

I like the idea of only having to manage the one shared folder (or 1 for each intake year) but how would this work for things like Folder Redirection of My Documents etc...

 

At the moment - with each user having their own shared folder - there is 1 GPO setup as everybody's home folder is in the format of \\SERVER\%USERNAME%

 

IF I decided on going down the direction of only having the route folder shared - would I then need multiple GPO's for each root folder for the Folder Redirection to work as they would no longer be in any consistent format?... e.g.:-

 

\\SERVER\YEAR 07\%USERNAME%

 

\\SERVER\YEAR 08\%USERNAME%

 

\\SERVER\YEAR 09\%USERNAME%

 

\\SERVER\YEAR 10\%USERNAME%

 

\\SERVER\YEAR 11\%USERNAME%

 

\\SERVER\YEAR 12\%USERNAME%

 

\\SERVER\YEAR 13\%USERNAME%

 

\\SERVER\STAFF\%USERNAME%

 

Thanks

 

Matt

Posted
Btw, on Server 2012/2012 R2 you could use the New-SmbShare PowerShell cmdlet instead of the old Net Share. :)

 

#Requires -Modules SmbShare

$dirs = Get-ChildItem -Path "D:\Test" -Directory

ForEach($dir in $dirs)
{
   New-SmbShare -Name $dir.Name -Path $dir.FullName -FullAccess Everyone -CachingMode None -FolderEnumerationMode AccessBased -ErrorAction SilentlyContinue
}

 

Hi Arthur,

 

Thanks for the script....

 

Is it possible within PowerShell for a popup box to come up each time the script is run to enter the Path Name on the fly rather then going in and editing the script? - Not the end of the world if not!

 

Thanks

 

Matt

Posted
Thanks guys...

 

The script is working perfectly now...

 

Following previous replies to this post - I'm just trying to work out the pro's and con's to setting up each home drive as a shared or just the root.

 

I like the idea of only having to manage the one shared folder (or 1 for each intake year) but how would this work for things like Folder Redirection of My Documents etc...

 

At the moment - with each user having their own shared folder - there is 1 GPO setup as everybody's home folder is in the format of \\SERVER\%USERNAME%

 

IF I decided on going down the direction of only having the route folder shared - would I then need multiple GPO's for each root folder for the Folder Redirection to work as they would no longer be in any consistent format?... e.g.:-

 

\\SERVER\YEAR 07\%USERNAME%

 

\\SERVER\YEAR 08\%USERNAME%

 

\\SERVER\YEAR 09\%USERNAME%

 

\\SERVER\YEAR 10\%USERNAME%

 

\\SERVER\YEAR 11\%USERNAME%

 

\\SERVER\YEAR 12\%USERNAME%

 

\\SERVER\YEAR 13\%USERNAME%

 

\\SERVER\STAFF\%USERNAME%

 

Thanks

 

Matt

 

In the GPO we set My Docs to redirect to the letter assigned in AD so if your AD home folder path looked like:

 

N \\SERVER\YEAR 07\%USERNAME%

 

The GPO for Documents would be N:\

Pictures would be : N:\My Pictures

Downloads: N:\Downloads

etc - with Windows creating the subfolders on first logon.

Posted

Eek - have you given every user their home area as a separately shared folder? That will absolutely rinse your server performance. As other have said, just have a root share, with sub shares below. As you stated, you'd need a separate GPO for each group for folder redirection, but having them in YEAR 7, YEAR 8 etc format will mean that you have to change these every year - don't make work for yourself!

 

Personally, I have all students in one big root folder so that I don't have to manage the sub-directories like this. The only thing that's harder is archiving, but if your naming convention is simple there's no problem there. Another advantage is that tools like NTFSFix and Chown work much better.

Posted

No you don't need separate GPO's for folder redirection.

 

Make use of the AD Home Directory field, and then you just set the Document Folder redirection to be %homeshare%

If you want to separate year groups, go for Year of Entry or Year of Exit rather than Year 7, Year 8 etc as you then don't have to rename them each summer, just add another folder.

Posted

Thanks Guys...

 

Yes we create a share for each users - I guess it's a habit that's stuck from the days of NT4.0 and never really known any different way of doing it - I agree there's a bit of work when using naming conventions such as Year group rather then intake year - but using tools / scripts doesn't really make that much work of it, I've updated the folders earlier on and it took about 5 minutes to do the whole school - I sometimes try and make a cup of tea on a normal school day that takes longer then that!

 

As staff have read only access to students folders it's far easier for them to look in a Year group folder then working out the intake year... also with 6th Form students and students coming to 6th Form from other schools would there "intake year" be set as 2015 which would be mixed with all our Year 7 students if they were joining us this year - or would there intake be 2010 when they would have been in Year 7 - it's far easier just to put them all in a Year 12 folder and all the Year 7's in a Year 7 folder.

 

I take on board the comments about the share folders and will look to implement that...

 

Thanks

 

Matt

Posted

Agreed on that point. Our naming convention is such that it's pretty unique but not personally identifiable - the staff tend to just ask the students what the account prefix for their year group is, or they ask us.

 

Just personal preference that, and means you don't have to update their homepaths and GPOs every year.

 

Changing the way shares are done should give your server a bit of a speed boost though, even though modern servers can most likely manage fine anyway a bit less system overhead is always good.

Posted
Agreed on that point. Our naming convention is such that it's pretty unique but not personally identifiable - the staff tend to just ask the students what the account prefix for their year group is, or they ask us.

 

Just personal preference that, and means you don't have to update their homepaths and GPOs every year.

 

Changing the way shares are done should give your server a bit of a speed boost though, even though modern servers can most likely manage fine anyway a bit less system overhead is always good.

 

I hadn't heard of any noticeable performance impact of many SMB shares on a server? Mainly I would say its more of a housekeeping thing so that when you browse via SMB you aren't bombarded my loads of shared folders. Saying that there are downsides to not using shares if you have your system setup with the old style homedir as My Documents you will be hit by the interesting "Everyones folder is called My Documents" issue!

 

Both methods have their merits, choose whichever works best in your scenario :)

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...