Created
January 27, 2020 23:01
-
-
Save yon2004/a27d84515949ea286850c891fb7b4ae5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Students = Get-ADGroupMember -Identity "Students" |Get-ADUser -Properties * | |
$Directories = @( | |
"Science", | |
"Maths", | |
"English" | |
) | |
ForEach ($Student in $Students){ | |
#Test for home directory | |
if (($Student.HomeDirectory -eq $null) -or ($Student.HomeDirectory -eq "")){ | |
Write-Host -ForegroundColor Yellow "$($Student.SamAccountName) Skipping as no home directory specified" | |
continue | |
} | |
#test if the folder exisits | |
if (Test-Path -Path $($Student.HomeDirectory)){ | |
ForEach ($Directory in $Directories){ | |
#if the path does not exsit create it | |
$FullPath = Join-Path -Path $($Student.HomeDirectory) -ChildPath $Directory | |
if (Test-Path -Path $FullPath){ | |
Write-Host "$($Student.SamAccountName) $Directory already exisits" | |
} else { | |
New-Item -ItemType Directory -Path $FullPath -WhatIf | |
Write-Host -ForegroundColor Green "$($Student.SamAccountName) $Directory Created" | |
} | |
} | |
}else{ | |
Write-Host -ForegroundColor Yellow "$($Student.SamAccountName) $($Student.HomeDirectory) Does not exisit" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment