Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .Synopsis
- For 1 or more computers, for a given folder root, create the folders, and the subfolders in the script here
- .Description
- Also see http://technet.microsoft.com/en-us/library/ff730951.aspx
- $session = New-PSSession -ComputerName "jan-pc"
- Enter-PSSession -Session $session
- Get-ACL "C:\sandbox\PowerShell\artefacts\subFolder" | Format-List
- Which returns eg
- Path : Microsoft.PowerShell.Core\FileSystem::C:\sandbox\PowerShell\artefacts\subFolder
- Owner : BUILTIN\Administrators
- Group : Jan-pc\denni_000
- Access : BUILTIN\Administrators Allow FullControl
- NT AUTHORITY\SYSTEM Allow FullControl
- BUILTIN\Users Allow ReadAndExecute, Synchronize
- NT AUTHORITY\Authenticated Users Allow Modify, Synchronize
- NT AUTHORITY\Authenticated Users Allow -536805
- Audit :
- Sddl : O:BAG:S-1-5-(snip)OICIID;0x1200a9;;;BU)(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)
- .Example
- New-Folder -ComputerName "dennis-pc","Jan-pc","emma-pc" -FolderRoot "\Test3"
- #>
- function New-Folder
- {
- Param (
- [Parameter(Mandatory=$true, Position=0)]
- [string[]]
- $ComputerName,
- [Parameter(Mandatory=$true, Position=1)]
- [string]
- $FolderRoot = "C:\TestFolder1",
- [Parameter(Mandatory=$false, Position=2)]
- [string]
- $UserName = "BUILTIN\users"
- )
- Begin {
- $fileRights = [System.Security.AccessControl.FileSystemRights]"FullControl"
- $InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit
- $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly
- $objType =[System.Security.AccessControl.AccessControlType]::Allow
- }
- Process {
- foreach ($computer in $ComputerName) {
- "Processing $computer..."
- Invoke-Command -ComputerName $computer -Credential $cred -ScriptBlock {
- param($FolderRoot1, $UserName1, $fileRights1, $InheritanceFlag1, $PropagationFlag1, $objType1)
- if (!(Test-Path -Path $FolderRoot1)) {
- "Creating folders in $FolderRoot1..."
- New-Item -ItemType directory -Path $FolderRoot1
- New-Item -ItemType directory -Path $FolderRoot1/Backup
- New-Item -ItemType directory -Path $FolderRoot1/Error
- }
- $objUser = New-Object System.Security.Principal.NTAccount($UserName1)
- $objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $fileRights1, $InheritanceFlag1, $PropagationFlag1, $objType1)
- $objACL = Get-ACL $FolderRoot1
- $objACL.AddAccessRule($objACE)
- Set-ACL $FolderRoot1 $objACL
- } -ArgumentList ($FolderRoot, $UserName, $fileRights, $InheritanceFlag, $PropagationFlag, $objType)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement