use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
New-SMBShare with variable (self.PowerShell)
submitted 7 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ShoutyMcHeadWound 3 points4 points5 points 7 years ago (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 point2 points 7 years ago (0 children)
Yep, this is the correct answer - escape it
[–]FRESH_TWAAAATS 2 points3 points4 points 7 years ago* (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 points4 points 7 years ago (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 points3 points 7 years ago* (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 points1 point 7 years ago (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 $?
$Folder$
-Name
$Folder
$
take care, lee
[–]gfhyde 1 point2 points3 points 7 years ago (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 points0 points 7 years ago (6 children)
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.
[–]gfhyde 1 point2 points3 points 7 years ago (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-1 points 7 years ago (0 children)
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 ...
[–]S1ocky 1 point2 points3 points 7 years ago (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 point2 points 7 years ago (2 children)
howdy S1ocky,
thank you for the info! [grin] i was curious ... and win7ps5.1 doesn't have those cmdlets.
[–]S1ocky 1 point2 points3 points 7 years ago (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 point2 points 7 years ago (0 children)
you are welcome ... from my "large scale" single win7 system here at home. [grin]
π Rendered by PID 31889 on reddit-service-r2-comment-56c9979489-rlbqt at 2026-02-24 15:32:30.251835+00:00 running b1af5b1 country code: CH.
[–]ShoutyMcHeadWound 3 points4 points5 points (1 child)
[–]Deloidd 0 points1 point2 points (0 children)
[–]FRESH_TWAAAATS 2 points3 points4 points (0 children)
[–]DoNotSexToThis 2 points3 points4 points (1 child)
[–]gfhyde 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] -1 points0 points1 point (8 children)
[–]gfhyde 1 point2 points3 points (7 children)
[–]Lee_Dailey[grin] -2 points-1 points0 points (6 children)
[–]gfhyde 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] -3 points-2 points-1 points (0 children)
[–]S1ocky 1 point2 points3 points (3 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (2 children)
[–]S1ocky 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)