Skip to content

Instantly share code, notes, and snippets.

@h-otter
Last active August 29, 2015 14:24
Show Gist options
  • Save h-otter/e9ecaf652dac4d39b722 to your computer and use it in GitHub Desktop.
Save h-otter/e9ecaf652dac4d39b722 to your computer and use it in GitHub Desktop.
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."
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment