Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function makeEnableUsersDirectory{
- [CmdletBinding()]
- param(
- [parameter(
- position = 0,
- mandatory = 0
- )]
- [string]
- $path
- )
- $enableUsers = get-aduser -filter {Enabled -eq $true} | select SamAccountName # Getting Enable Users
- for ($i = 0; $i -lt $enableUsers.length; $i++)
- {
- $newDirectory = Join-Path $path $enableUsers[$i].SamAccountName
- New-Item $newDirectory -ItemType directory # Make New Directory
- if (Test-Path -Path $newDirectory)
- {
- $user = $enableUsers[$i].SamAccountName + $domain
- icacls $newDirectory /setowner $user # Set Owner
- }
- else
- {
- Write-Warning "File not exist. Please check path you tried."
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement