Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Create-HomeDrive
- {
- param(
- [Parameter(Position=0,
- Mandatory=$true,
- ValueFromPipeline=$true,
- ValueFromPipelineByPropertyName=$true)]
- [string]$Username,
- [Parameter(Position=1,
- Mandatory=$true,
- ValueFromPipeline=$true,
- ValueFromPipelineByPropertyName=$true)]
- [ValidateSet("PN","WG","WAI")]
- [string]$Campus
- )
- # Usage: Create-HomeDrive -Username <StudentID> -Campus <CampusCode>
- # Example: Create-HomeDrive -Username 123456789 -Campus PN
- # Generates a folder for the specified username on the replicated folder group for the specified campus.
- # As this is replicated and part of the domain namespace '\\ucol.ac.nz\HomeDrives', this can be accessed
- # via the namespace address and the user hit the local campus copy of their home drive data when roaming
- # between campuses.
- # This also grants 'Modify' permissions on the home folder. It should be noted that the parent folders
- # in this path do not have 'List Contents' rights for non-administrators, so students can't enumerate other
- # home folders.
- #$path = "\\pn-student2\Students$\" + $Campus + "\" + $Username
- $path = "D:\Temp\TestOutput\" + $Campus + "\" + $Username
- if (!(Test-Path $path))
- {
- New-Item -Path $path -type Directory -Force
- $acl = Get-Acl $path
- $ace = New-Object System.Security.AccessControl.FileSystemAccessRule($username, "Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
- $acl.SetAccessRule($ace)
- Set-Acl -path $Path -AclObject $acl
- $pnpath = "\\pn-student2\Students$\" + $Campus + "\" + $Username
- $wgpath = "\\wg-student2\Students$\" + $Campus + "\" + $Username
- $waipath = "\\wai-student2\Students$\" + $Campus + "\" + $Username
- $applyquota = {param($path); New-FSRMQuota -Path $Path -Size 1.0GB}
- while ($pnapplied -eq $false)
- {
- if (!(Test-Path $pnpath))
- {
- Start-Sleep -s 1
- }
- elseif ((Test-Path $pnpath))
- {
- Invoke-Command -ComputerName "PN-Student2" -ScriptBlock $applyquota
- $pnapplied = $true
- }
- }
- while ($wgapplied -eq $false)
- {
- if (!(Test-Path $wgpath))
- {
- Start-Sleep -s 1
- }
- elseif ((Test-Path $wgpath))
- {
- Invoke-Command -ComputerName "WG-Student2" -ScriptBlock $applyquota
- $wgapplied = $true
- }
- }
- while ($waiapplied -eq $false)
- {
- if (!(Test-Path $waipath))
- {
- Start-Sleep -s 1
- }
- elseif ((Test-Path $waipath))
- {
- Invoke-Command -ComputerName "WAI-Student2" -ScriptBlock $applyquota
- $waiapplied = $true
- }
- }
- }
- elseif ((Test-Path $Path))
- {
- Add-LogEntry "Home drive already exists for user $($Username)"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement