Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Home folder share script problem

$
0
0

Hey Guys quick question:

Working on a project for school, and I’m running into an issue with setting up user’s home folders.

I use this script to set the path in the user profile page:

Get-ADUser -Filter * -SearchBase "OU=OU_ORGA,DC=tim,DC=hik,DC=com" | Foreach-Object{ $sam = $_.SamAccountName Set-ADuser -Identity $_ -HomeDrive "H:" -HomeDirectory "\DC1home$$sam" Write-Host -ForegroundColor Green "Home folder set for $($sam)" } 

As you can see, it’s filled in perfectly, but the user folder doesn’t show up in the home$ folder: http://i.imgur.com/RuNKA4q.png

When I put a space behind the path and delete it again, then click confirm, the path shows up in the folder.

What the hell am I doing wrong?

Here’s the code to make the folder and share it (let me know if there is a simpler way to do it other than this wall of code btw…):

#Local path $FolderPath = 'c:Home$' $Shares=[WMICLASS]'WIN32_Share' #Share name $ShareName='Home$' #Create folder New-Item -type directory -Path $FolderPath #Create share rights #Define a trustee (person/group to give access right) $trustee = ([wmiclass]‘Win32_trustee’).psbase.CreateInstance() $trustee.Domain = "NT Authority" $trustee.Name = “Authenticated Users” #Define an access control entry (permission-entry) $ace = ([wmiclass]‘Win32_ACE’).psbase.CreateInstance() #Modify-rights $ace.AccessMask = 1245631 #Inheritance for folders and files $ace.AceFlags = 3 $ace.AceType = 0 #Assign rights to Authenticated users ($trustee) $ace.Trustee = $trustee $trustee2 = ([wmiclass]‘Win32_trustee’).psbase.CreateInstance() $trustee2.Domain = "BUILTIN" #Or domain name $trustee2.Name = “Administrators” $ace2 = ([wmiclass]‘Win32_ACE’).psbase.CreateInstance() #Full control $ace2.AccessMask = 2032127 $ace2.AceFlags = 3 $ace2.AceType = 0 #Assign rights to Administrators ($trustee2) $ace2.Trustee = $trustee2 #Create ACL/security descriptor. This is the security-definitions that you set on the share. $sd = ([wmiclass]‘Win32_SecurityDescriptor’).psbase.CreateInstance() #Specify that a DACL (ACL/security/permissions) are available, so the share isn't set to full access for everyone $sd.ControlFlags = 4 #Add our rules $sd.DACL = $ace, $ace2 #Set Administrators ($trustee2) as owner and group of ITEM (will be the share) $sd.group = $trustee2 $sd.owner = $trustee2 #Create share with the security rules $shares.create($FolderPath, $ShareName, 0, 100, "Description", "", $sd) | Out-Null #Get NTFS permissiongs $Acl = Get-Acl $FolderPath #Disable inheritance and clear permissions $Acl.SetAccessRuleProtection($True, $False) #Define NTFS rights $rule = New-Object System.Security.AccessControl.FileSystemAccessRule('Administrators','FullControl','ContainerInherit, ObjectInherit', 'None', 'Allow') $Acl.AddAccessRule($rule) $rule = New-Object System.Security.AccessControl.FileSystemAccessRule('SYSTEM','FullControl','ContainerInherit, ObjectInherit', 'None', 'Allow') $Acl.AddAccessRule($rule) $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Authenticated Users",@("ReadData", "AppendData", "Synchronize"), "None", "None", "Allow") $Acl.AddAccessRule($rule) $rule = New-Object System.Security.AccessControl.FileSystemAccessRule('CREATOR OWNER','FullControl','ContainerInherit, ObjectInherit', 'InheritOnly', 'Allow') $Acl.AddAccessRule($rule) #Save ACL changes (NTFS permissions) Set-Acl $FolderPath $Acl | Out-Null #Show ACL so user can verify changes Get-Acl $FolderPath | Format-List 

Any help is very welcome! thanks!

submitted by /u/MyOtherRideIsYosista
[link] [comments]

The post Home folder share script problem appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images