Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Create-HomeDrive
  2. {
  3.     param(
  4.  
  5.         [Parameter(Position=0,
  6.             Mandatory=$true,
  7.             ValueFromPipeline=$true,
  8.             ValueFromPipelineByPropertyName=$true)]
  9.         [string]$Username,
  10.  
  11.         [Parameter(Position=1,
  12.             Mandatory=$true,
  13.             ValueFromPipeline=$true,
  14.             ValueFromPipelineByPropertyName=$true)]
  15.         [ValidateSet("PN","WG","WAI")]
  16.         [string]$Campus
  17.  
  18.         )
  19.  
  20.     # Usage: Create-HomeDrive -Username <StudentID> -Campus <CampusCode>
  21.     # Example: Create-HomeDrive -Username 123456789 -Campus PN
  22.  
  23.     # Generates a folder for the specified username on the replicated folder group for the specified campus.
  24.     # As this is replicated and part of the domain namespace '\\ucol.ac.nz\HomeDrives', this can be accessed
  25.     # via the namespace address and the user hit the local campus copy of their home drive data when roaming
  26.     # between campuses.
  27.  
  28.     # This also grants 'Modify' permissions on the home folder. It should be noted that the parent folders
  29.     # in this path do not have 'List Contents' rights for non-administrators, so students can't enumerate other
  30.     # home folders.
  31.  
  32.     #$path = "\\pn-student2\Students$\" + $Campus + "\" + $Username
  33.     $path = "D:\Temp\TestOutput\" + $Campus + "\" + $Username
  34.     if (!(Test-Path $path))
  35.     {
  36.         New-Item -Path $path -type Directory -Force
  37.  
  38.         $acl = Get-Acl $path
  39.         $ace = New-Object System.Security.AccessControl.FileSystemAccessRule($username, "Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
  40.         $acl.SetAccessRule($ace)
  41.         Set-Acl -path $Path -AclObject $acl
  42.  
  43.         $pnpath = "\\pn-student2\Students$\" + $Campus + "\" + $Username
  44.         $wgpath = "\\wg-student2\Students$\" + $Campus + "\" + $Username
  45.         $waipath = "\\wai-student2\Students$\" + $Campus + "\" + $Username
  46.  
  47.         $applyquota = {param($path); New-FSRMQuota -Path $Path -Size 1.0GB}
  48.  
  49.         while ($pnapplied -eq $false)
  50.         {
  51.             if (!(Test-Path $pnpath))
  52.             {
  53.                 Start-Sleep -s 1
  54.             }
  55.             elseif ((Test-Path $pnpath))
  56.             {
  57.                 Invoke-Command -ComputerName "PN-Student2" -ScriptBlock $applyquota
  58.                 $pnapplied = $true
  59.             }
  60.         }
  61.  
  62.         while ($wgapplied -eq $false)
  63.         {
  64.             if (!(Test-Path $wgpath))
  65.             {
  66.                 Start-Sleep -s 1
  67.             }
  68.             elseif ((Test-Path $wgpath))
  69.             {
  70.                 Invoke-Command -ComputerName "WG-Student2" -ScriptBlock $applyquota
  71.                 $wgapplied = $true
  72.             }
  73.         }
  74.  
  75.         while ($waiapplied -eq $false)
  76.         {
  77.             if (!(Test-Path $waipath))
  78.             {
  79.                 Start-Sleep -s 1
  80.             }
  81.             elseif ((Test-Path $waipath))
  82.             {
  83.                 Invoke-Command -ComputerName "WAI-Student2" -ScriptBlock $applyquota
  84.                 $waiapplied = $true
  85.             }
  86.         }
  87.  
  88.     }
  89.     elseif ((Test-Path $Path))
  90.     {
  91.         Add-LogEntry "Home drive already exists for user $($Username)"
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement