Tag Archives: Administration

Random Password Generator

Generates strong passwords

PS1:

$length = 9
For ($a=48;$a –le 122;$a++) {$ascii+=,[char][byte]$a }
Function GET-Temppassword() {

Param(

[int]$length=10,

[string[]]$sourcedata

)

For ($loop=1; $loop –le $length; $loop++) {

            $TempPassword+=($sourcedata | GET-RANDOM)

            }

return $TempPassword

}

For ($a=48;$a –le 122;$a++) {$ascii+=,[char][byte]$a }

GET-Temppassword –length $Length –sourcedata $ascii

Optional Function:

Function GET-Temppassword() {

Param(

[int]$length=10,

[string[]]$sourcedata

)

For ($loop=1; $loop –le $length; $loop++) {

            $TempPassword+=($sourcedata | GET-RANDOM)

            }

return $TempPassword

}

ZIP:

 

NTFS Security Inheritance Export Script

import-module Ntfssecurity
$lokatie = "\Domain.localdfs"
$header = "Fullname;InheritanceEnabled"
$CSV = "C:file.csv"
add-content -value $header -path $CSV
$list = Get-Childitem $lokatie -recurse | where {$_.psiscontainer -eq $true}
foreach ($Item in $list){
$export = get-inheritance -path $item.fullname
foreach ($object in $export){
$outinfo = $item.fullname + ";" + $object.inheritanceEnabled
add-content -value $outinfo -path $CSV}}

 

NTFSSecurity

Restore exported ACL on folder

Import-Module ActiveDirectory

$csv = gci .CSVFiles* -Include *.csv

$list += import-csv $CSV -Delimiter ';'
foreach ($entry in $list){
$Folderpath=$entry.'Folder path'
$Identity=$entry.IdentityReference
$AccessControlType=$entry.AccessControlType
$IsInherited=$entry.IsInherited
$Inheritanceflags=$entry.InheritanceFlags
$PropagationFlags=$entry.PropagationFlags
$FileSystemRights=$entry.FileSystemRights

$OldACL = get-acl $Folderpath
$Newpermission = ($Identity,$FileSystemRights,$Inheritanceflags,$PropagationFlags,$AccessControlType)
write-host $Newpermission
$AccessRule = new-object System.Security.AccessControl.FileSystemAccessRule $NewPermission
$OldACL.SetAccessRule($AccessRule)
$OldAcl | Set-ACL $Folderpath

Export permissions to CSV file

$OutFile = "C:Permissions.csv"
$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"
Del $OutFile
Add-Content -Value $Header -Path $OutFile

$RootPath = "C:Test"

$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}

foreach ($Folder in $Folders){
$ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access }
Foreach ($ACL in $ACLs){
$OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference + "," + $ACL.AccessControlType + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
Add-Content -Value $OutInfo -Path $OutFile
}}

Rechten op nieuwe folder uitdelen

new-item -path h: -name Folder1Folder2 -type directory
$locatie=('\Domain.localdfs$deelnemerusers$samaccountnameFolder1')
Sleep -s 30

$Domain = "$Domain$Groepsnaam"
$NewACL = get-acl $locatie
$Newpermission = ($Domain,"Modify, Synchronize","ContainerInherit, ObjectInherit", "None","Allow")
$AccessRule = new-object System.Security.AccessControl.FileSystemAccessRule $NewPermission
$NewACL.SetAccessRule($AccessRule)
$NewAcl | Set-ACL $locatie

Volgnummer bijhouden in een CSV file

Import-module 'ActiveDirectory'
 $getadusers = @()
 $filter = @()
 $samaccountnamelijst = @()
 $Header = 'Samaccountname'
 $CSV = '.\Gemeentenet.csv'
 $Extension = $null
 $import = @()
 Add-Content -Value $Header -Path $CSV
 $getadusers = Get-aduser -filter *
 foreach ($entry in $getadusers){if ($entry -ne $null){$samaccountnamelijst += $entry.samaccountname}}
 foreach ($sam in $samaccountnamelijst){Add-Content -Value $sam -Path $CSV}
 $Deelnemerlijst = @()
 $allusers = import-csv $csv
 foreach ($Deelnemeruser in $allusers){if ($Deelnemeruser -match $deelnemer){$Deelnemerlijst += $Deelnemeruser}}
 $Deelnemerlijst | export-csv .\$Deelnemer.csv

$entry = $null
$username = 'othext'
 $CSV = '.\Gemeentenet.csv'
 $import = @()
 $filter = @()
 $import = import-csv $csv
 foreach ($entry in $import){if ($entry -match $username){$filter += $entry.samaccountname}}
 $filter = $filter -split "@{samaccountname=" |sort
 $filter = $filter -split "$username" | sort
 $filter = $filter -split "}" | Sort -Descending
 $nummer = [int]$filter[0]
 $nummer++

Add-content -Value $volledigesamaccountname -path $csv