Skip to content

Instantly share code, notes, and snippets.

@yon2004
Created January 27, 2020 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yon2004/a27d84515949ea286850c891fb7b4ae5 to your computer and use it in GitHub Desktop.
Save yon2004/a27d84515949ea286850c891fb7b4ae5 to your computer and use it in GitHub Desktop.
$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