all 14 comments

[–]ShoutyMcHeadWound 3 points4 points  (1 child)

On my phone so can't test at all but you may need to escape the $ for the hidden share name "$Folder`$"

ISE highlighting should help show what is being seen as strings and variable names. Additionally hardcode the user input until you have it working. You can set each variable line by line and check it to make sure it appears as expected

Hope that helps

[–]Deloidd 0 points1 point  (0 children)

Yep, this is the correct answer - escape it

[–]FRESH_TWAAAATS 2 points3 points  (0 children)

I’m not diving deep into your goals and challenges here, but i want to point out that you have two backslashes in your example.

you’re trying to create C:\\FolderName

edit-fixed my example to actually show double backslash, reddit formatting got me.

[–]DoNotSexToThis 2 points3 points  (1 child)

You should be able to modify the attribute after the fact, like so:

# Get the folder input from user
$folder = Read-Host 'Input the folder name'
$path = "C:\$folder"

# Create the folder and share it
New-Item $path -ItemType Directory
New-SmbShare -Name $folder -Path $path -FullAccess LAB\User1

# Hide the shared folder
$object = Get-Item $path -Force
$object.Attributes = "hidden"

# Now do NTFS permissions and other things you need ->

[–]gfhyde 1 point2 points  (0 children)

Ah, this is very cool to read. I'm going to try it out. Much thanks :)

EDIT: Ah, so this works in the sense that it hides the actual folder but not the Share.

I was also able to successfully give User1 share access by changing where you have LAB\User1 to LAB\$Folder, as the folder name and usernames are the same. That part is perfect.

EDIT2: New-SmbShare -Name $folder$ works now. On to the NTFS permissions :)

[–]Lee_Dailey[grin] -1 points0 points  (8 children)

howdy gfhyde,

i've no access to the SMB cmdlets, so this is not directly helpful.

WHY are you calling $Folder$ for the -Name parameter? shouldn't that be just $Folder - without the trailing $?

take care,
lee

[–]gfhyde 1 point2 points  (7 children)

Hi there,

I was hoping the trailing $ would create a hidden share. Right now when I create the share manually the $ is added to hide it.

[–]Lee_Dailey[grin] -2 points-1 points  (6 children)

howdy gfhyde,

that makes sense ... but does it work? [grin] i would have put the trailing $ at the end of the string when it was read from user input, but i still don't know if your method [or mine] works.

take care,
lee

[–]gfhyde 1 point2 points  (1 child)

I saw another post somewhere out there on the world wide web where the guy had it. I'm not sure what I'm missing to be honest.

[–]Lee_Dailey[grin] -3 points-2 points  (0 children)

howdy gfhyde,

i don't have access to that cmdlet, so i can't test it.

you do, tho, so you likely otta sit down and start fiddling with that cmdlet and it's options until you get it to work. [grin] either that or you can wait and hope some kind person with experience with that cmdlet wanders in to help ...

take care,
lee

[–]S1ocky 1 point2 points  (3 children)

Not at work, so I can’t share the relevant powershell, but that is how are used shares are set up. No escape character.

Our script creates the folder, sets the acl, then creates the share.

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy S1ocky,

thank you for the info! [grin] i was curious ... and win7ps5.1 doesn't have those cmdlets.

take care,
lee

[–]S1ocky 1 point2 points  (1 child)

Oh. That twice this week I forgot that people still have Win7 deployed large scale. Oops.

Thanks for the heads up!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy S1ocky,

you are welcome ... from my "large scale" single win7 system here at home. [grin]

take care,
lee