asked on
$root = "C:\Users\a.narasimha.s\Desktop\foldertest1"
ForEach ($dir in (Get-ChildItem -Path "$root\*\" | ?{$_.PSIsContainer} | Select -Expand Name)){
New-Item -Path "$dir\folder1" -ItemType Directory | Out-Null
New-Item -Path "$dir\folder2" -ItemType Directory | Out-Null
New-Item -Path "$dir\1" -ItemType Directory | Out-Null
New-Item -Path "$dir\2" -ItemType Directory | Out-Null
}
ASKER
$root = "C:\Users\a.narasimha.s\Desktop\foldertest1"
Get-ChildItem -Path "$root\*\" | Where-Object { $_.PSIsContainer } | ForEach-Object {
$dir = $_.FullName
$folder = New-Item -Path "$dir\folder1" -ItemType Directory
$acl = Get-Acl $folder.FullName
$acl.SetAccessRuleProtection($true, $true)
$acl.Access | Where-Object { $_.IdentityReference -eq 'domain\somegroup' } | ForEach-Object {
$acl.RemoveAccessRule($_)
}
$ace = New-Object System.Security.AccessControl.FileSystemAccessRule('domain\somegroup', 'ReadAndExecute,Synchronize', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
$acl.AddAccessRule($ace)
Set-Acl $folder.FullName -AclObject $acl
$folder = New-Item -Path "$dir\folder2" -ItemType Directory
$acl = Get-Acl $folder.FullName
$acl.SetAccessRuleProtection($true, $true)
$acl.Access | Where-Object { $_.IdentityReference -eq 'domain\somegroup' } | ForEach-Object {
$acl.RemoveAccessRule($_)
}
$ace = New-Object System.Security.AccessControl.FileSystemAccessRule('domain\somegroup', 'ReadAndExecute,Synchronize', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
$acl.AddAccessRule($ace)
Set-Acl $folder.FullName -AclObject $acl
$folder = New-Item -Path "$dir\1" -ItemType Directory
$folder = New-Item -Path "$dir\2" -ItemType Directory
}
ASKER
ASKER
ASKER
$acl.Access | Where-Object { $_.IdentityReference -eq 'domain\somegroup' } | ForEach-Object {
Write-Host "Removining ACE for $($_.IdentityReference)"
$acl.RemoveAccessRule($_)
}
ASKER
$acl = Get-Acl $folder.FullName
$acl.SetAccessRuleProtection($true, $true)
Set-Acl $folder.FullName -AclObject $acl
$acl = Get-Acl $folder.FullName
$acl.Access | Where-Object { $_.IdentityReference -eq 'domain\somegroup' } | ForEach-Object {
$acl.RemoveAccessRule($_)
}
$ace = New-Object System.Security.AccessControl.FileSystemAccessRule('domain\somegroup', 'ReadAndExecute,Synchronize', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
$acl.AddAccessRule($ace)
Set-Acl $folder.FullName -AclObject $acl
ASKER
ASKER
ASKER
$ace = New-Object System.Security.AccessControl.FileSystemAccessRule('domain\somegroup', 'ReadAndExecute,Synchronize', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
$acl = Get-Acl "C:\Users\a.narasimha.s\Desktop\foldertest1\something\folder1"
$acl.Access | Where-Object { $_.IdentityReference -eq 'domain\somegroup' } | ForEach-Object {
Write-Host "Removing ACL for $($_.IdentityReference)"
$acl.RemoveAccessRule($_)
}
It is very, very important you get the terminology right here. If you tell me there are inherited access control entries on a folder which just had protection enabled I'll have to ask more questions about whether or not protection is enabled. ASKER
ASKER
$root = "C:\Users\a.narasimha.s\Desktop\foldertest1"
Get-ChildItem -Path "$root\*\" | Where-Object { $_.PSIsContainer } | ForEach-Object {
$dir = $_.FullName
$folder = New-Item -Path "$dir\folder1" -ItemType Directory
$acl = Get-Acl $folder.FullName
$acl.SetAccessRuleProtection($true, $true)
$acl.Access | Where-Object { $_.IdentityReference -eq 'Domain\Group1' } | ForEach-Object {
$acl.RemoveAccessRule($_)
}
$ace = New-Object System.Security.AccessControl.FileSystemAccessRule('Domain\Group', 'ReadAndExecute,Synchronize', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
$acl.AddAccessRule($ace)
Set-Acl $folder.FullName -AclObject $acl
$root = "C:\Users\a.narasimha.s\Desktop\foldertest1"
Get-ChildItem -Path "$root\*\" | Where-Object { $_.PSIsContainer } | ForEach-Object {
$dir = $_.FullName
$folder = New-Item -Path "$dir\folder1" -ItemType Directory
$acl = Get-Acl $folder.FullName
$acl.SetAccessRuleProtection($true, $true)
Set-Acl $folder.FullName -AclObject $acl
$acl = Get-Acl $folder.FullName
$acl.Access | Where-Object { $_.IdentityReference -eq 'Domain\Group1' } | ForEach-Object {
$acl.RemoveAccessRule($_)
}
$ace = New-Object System.Security.AccessControl.FileSystemAccessRule('Domain\Group', 'ReadAndExecute,Synchronize', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
$acl.AddAccessRule($ace)
Set-Acl $folder.FullName -AclObject $acl
ASKER
ASKER
ASKER
$acl = Get-Acl "C:\Users\a.narasimha.s\Desktop\foldertest1\something\folder1"
$acl.Access | Where-Object { $_.IdentityReference -eq 'domain\somegroup' } | ForEach-Object {
Write-Host "Removing ACL for $($_.IdentityReference)"
$acl.RemoveAccessRule($_)
}
We categorically need to know if the snippet is selecting the correct rule to remove.
ASKER
$acl = Get-Acl "C:\Users\a.narasimha.s\Desktop\foldertest1\something\folder1"
$acl.Access | Where-Object { $_.IdentityReference.Value.ToString() -like '*\somegroup' } | ForEach-Object {
Write-Host "Removing ACL for $($_.IdentityReference)"
$acl.RemoveAccessRule($_)
}
ASKER
ASKER
$acl = Get-Acl "C:\Users\a.narasimha.s\Desktop\foldertest1\something\folder1"
$acl.Access | Where-Object { $_.IdentityReference.Value.ToString() -like '*\somegroup' } | ForEach-Object {
$_
$acl.RemoveAccessRule($_)
}
ASKER
ASKER
$acl = Get-Acl "C:\Users\a.narasimha.s\Desktop\foldertest1\123\doc"
$acl = Get-Acl "C:\Users\a.narasimha.s\Desktop\foldertest1\123\doc"
$acl.Access | Where-Object { $_.IdentityReference.Value.ToString() -like '*\DL-WGK-US-Houston-Projects-XXXXXX-RW-TESTnew12' } | ForEach-Object {
$_
$acl.RemoveAccessRule($_)
}
Set-Acl "C:\Users\a.narasimha.s\Desktop\foldertest1\123\" -AclObject $acl
Get-Acl "C:\Users\a.narasimha.s\Desktop\foldertest1\123\" |
Select-Object -ExpandProperty Access
ASKER
ASKER
$root = "C:\Users\a.narasimha.s\Desktop\foldertest1"
Get-ChildItem -Path "$root\*\" | Where-Object { $_.PSIsContainer } | ForEach-Object {
$dir = $_.FullName
$folder = New-Item -Path "$dir\doc" -ItemType Directory
$acl = Get-Acl $folder.FullName
$acl.SetAccessRuleProtection($true, $true)
$acl.Access | Where-Object { $_.IdentityReference.Value.ToString() -like '*\DL-WGK-US-Houston-Projects-XXXXXX-RW-TESTnew12' } | ForEach-Object {
Write-Host "Removing ACL for $($_.IdentityReference)"
$acl.RemoveAccessRule($_)
}
$ace = New-Object System.Security.AccessControl.FileSystemAccessRule('domain\DL-WGK-US-Houston-Projects-XXXXXX-RW-TESTnew', 'ReadAndExecute,Synchronize', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
$acl.AddAccessRule($ace)
Set-Acl $folder.FullName -AclObject $acl
}
$acl = Get-Acl "C:\Users\a.narasimha.s\Desktop\foldertest1\123\doc"
$acl.Access | Where-Object { $_.IdentityReference.Value.ToString() -like '*\DL-WGK-US-Houston-Projects-XXXXXX-RW-TESTnew12' } | ForEach-Object {
$_
$acl.RemoveAccessRule($_)
}
Set-Acl "C:\Users\a.narasimha.s\Desktop\foldertest1\123\" -AclObject $acl
Get-Acl "C:\Users\a.narasimha.s\Desktop\foldertest1\123\" |
Select-Object -ExpandProperty Access
ASKER
Set-Location "C:\Users\a.narasimha.s\Desktop\98"
$csvFile = "C:\Users\a.narasimha.s\Desktop\importfolders.csv"
$create = Import-CSV $csvFile
function DoPermissions
{
param( $permissionGroup, $folder, $level)
$toAdd = $permissionGroup -split ";"
Write-Host $folder
foreach ($item in $toAdd)
{
$acl = (Get-Item $folder).GetAccessControl('Access')
$ar = New-Object System.Security.AccessControl.FileSystemAccessRule($item, $level, 'ContainerInherit,ObjectInherit','None','Allow')
$acl.SetAccessRule($ar)
Set-ACL -path $folder -AclObject $acl
}
}
foreach ($folder in $create)
{
$fullPath = $folder.folder #$path + $folder.folder
if (!(Test-Path $fullPath)) {New-Item -ItemType Directory -Path $fullPath}
if ($folder.full_control) {DoPermissions $folder.full_control $fullPath "FullControl"}
if ($folder.modify) {DoPermissions $folder.modify $fullPath "Modify"}
if ($folder.read_execute) {DoPermissions $folder.read_execute $fullPath "ExecuteFile"}
if ($folder.list_folder_content) {DoPermissions $folder.list_folder_content $fullPath "ListDirectory"}
if ($folder.read) {DoPermissions $folder.read $fullPath "ReadData"}
if ($folder.write) {DoPermissions $folder.write $fullPath "Write"}
}
ASKER
$folder = "C:\Users\IBM_ADMIN\Desktop\foldertest"
$subfolders = "Volvo","Skoda","Tesla"
$file = Import-Csv 'C:\Users\IBM_ADMIN\Desktop\foldertest\import.csv' -Delimiter ';'
$file |
% {
$path = Join-Path $folder $_.Letter;
New-Item -Path $path -Name $_.Name -Type Directory
}
foreach ($subfolder in $subfolders)
{
$file | %{
$path2 = Join-Path $folder $_.Letter;
$path3 = Join-Path $path2 $_.Name;
New-Item -Path $path3\$subfolder -Type Directory
}
}
A scripting language is a programming language that supports scripts, programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator. Scripting languages are often interpreted (rather than compiled). Primitives are usually the elementary tasks or API calls, and the language allows them to be combined into more complex programs. Environments that can be automated through scripting include software applications, web pages within a web browser, the shells of operating systems (OS), embedded systems, as well as numerous games. A scripting language can be viewed as a domain-specific language for a particular environment; in the case of scripting an application, this is also known as an extension language.
TRUSTED BY
This might need a bit of tweaking, I haven't tested it.
Open in new window