FCMigrationPub.ps1


posted by aduplessis
03-14-2010

Downloads: 349
File size: 11.7kB
Views: 1,772

Embed
FCMigrationPub.ps1
  1. #region File Cluster Migration Script Description 
  2. ## ===================================================================== 
  3. ## Title       : File Cluster Migration Script (FCMigrationPub.ps1) 
  4. ## Description : Create cluster shares and assign owner to home dir. 
  5. ## Author      : Anthony Duplessis 
  6. ## Date        : 1/24/2010 
  7. ## Input       : Make sure the below variable are set correctly. 
  8. ## Variables   : 
  9. ## 
  10. ## $body - Body of email message 
  11. ## $Count - Used to count number of users to process from text file 
  12. ## $DirExists - Directory Exists Counter 
  13. ## $DirNoExists - Directory does not exist counter 
  14. ## $emailFrom - Email from email address 
  15. ## $emailTo - Email to email address 
  16. ## $HomeDirModified - Directory owner set counter 
  17. ## $HomePath - Variable that must be set for each server - path to home folder root 
  18. ## $IcaclsPath - Static path to Icacls.exe 
  19. ## $InputFile - Variable that must be set for each server - path and name of file with user account names. 
  20. ## $NetPath - Static path to Net.exe 
  21. ## $RunCompact - Variable to invoke to run Compact.exe to un-compress files 
  22. ## $RunIcaclsCommand - Variable to invoke to set owner of directory and files of home folders 
  23. ## $Sharename - Name of share to create a combination of $UserName and "$" dollar sign 
  24. ## $ShareReportPath - path and file name for share creation report 
  25. ## $SharesCreated - Number of shares created counter 
  26. ## $smtp - object definition 
  27. ## $smtp.Send - send routine 
  28. ## $smtpServer - SMTP Server name 
  29. ## $subject - email subject 
  30. ## $Total - total count of users in file 
  31. ## $UserDir - variable of the users hole directory path 
  32. ##                                    
  33. ## Output      : to log file as defined in $ShareReportPath variable 
  34. ## Usage       : 
  35. ##               1. Edit the variables below for the correct locations, file names, email addresses and email text  
  36. ##               of the variables in the VARIABLES THAT REQUIRE MODIFICATIONS section. 
  37. ##  
  38. ##               The script will scan the users to be modified from the file 
  39. ##               - count the number of users 
  40. ##                 - verify that there home directory exists 
  41. ##                 - create their home share 
  42. ##               - make the user the owner of their home directory and directories and files within 
  43. ##               - Un-compress the files and directories 
  44. ##               - Send an email notification of the completion of the script 
  45. ##             
  46. ## Notes       : 
  47. ## Change log  : 
  48. ## ===================================================================== 
  49. #endregion 
  50.  
  51. #region Initialize Variables 
  52. ## ===================================================================== 
  53. ## Initialize Variables 
  54. ## ===================================================================== 
  55. Clear-Host 
  56. ## ===================================================================== 
  57. ##                                  VARIABLES THAT REQUIRE MODIFICATIONS 
  58. ## ===================================================================== 
  59. $HomePath="N:\HomeDirs\" 
  60. $InputFile="D:\HomeDirs.txt" 
  61. $ShareReportPath="D:\Shares.log" 
  62. $emailFrom = "FileClusterMigration@company.com" 
  63. $emailTo = "superadmin@company.com,admin@company.com" 
  64. $smtpServer = "smtp.company.com" 
  65.  
  66. ## ===================================================================== 
  67. ## No changes below this line 
  68. ## ===================================================================== 
  69. $NetPath="C:\Windows\System32\NET.exe SHARE " 
  70. $IcaclsPath="C:\Windows\System32\ICACLS.exe " 
  71. $subject = "" 
  72. $body = "" 
  73. $RunCompact="" 
  74. $Sharename=$UserName+"$" 
  75. $SharesCreated=
  76. $HomeDirModified=
  77. $DirExists=
  78. $DirNoExists=
  79. #endregion 
  80.  
  81. #region Display Script Title 
  82. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  83. Write-Host "             F I L E  C L U S T E R  M I G R A T I O N  T O O L" -ForegroundColor Green 
  84. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  85. #endregion 
  86.  
  87. #region Loop to Count items in text file and verify the home directory exists 
  88. ## ======================================================================== 
  89. ## "Loop to Count items in text file and verify the home directory exists" 
  90. ## ======================================================================== 
  91.  
  92. $body = @" 
  93. The File Cluster Migration script count and verify directory has started. 
  94. "@ 
  95. $subject = "FCMigration Script Count and Directory Verification Routine Started." 
  96. $smtp = new-object Net.Mail.SmtpClient($smtpServer
  97. $smtp.Send($emailFrom, $emailTo, $subject, $body
  98.  
  99. Foreach ($UserName in (Get-Content $InputFile)) 
  100.   $Count=$Count+
  101.   $Total=$Count 
  102.   $UserDir=$HomePath+$Username 
  103.  
  104.   if (Test-Path $UserDir
  105.     $DirExists=$DirExists+
  106. else 
  107.     $DirNoExists=$DirNoExists+
  108.     Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  109.     Write-Host "The Following Directories do not match the supplied User ID" -ForegroundColor Yellow 
  110.     Write-Host " " 
  111.     Write-Host "$UserDir, Does Not Exist for User ID: $UserName" -ForegroundColor Red 
  112.     Write-Host " " 
  113.  
  114.  
  115. Write-Host "��������������������������������������������������������������������������������"  -ForegroundColor Green 
  116. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  117. Write-Host " Total Directories Excpected - " $Total -ForegroundColor Green 
  118. Write-host "     Total Directories Found - " $DirExists -ForegroundColor Green 
  119. Write-host "   Total Directories Missing - " $DirNoExists -ForegroundColor Red 
  120. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  121.  
  122. If ($DirNoExists -gt 0) 
  123. Write-Host "��������������������������������������������������������������������������������"  -ForegroundColor Red 
  124. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  125. Write-Host "                 FIX THE ABOVE ERRORS AND RE-RUN THIS SCRIPT!" -ForegroundColor Yellow 
  126. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  127.    
  128. Exit 
  129. Else 
  130.  
  131. #endregion 
  132.  
  133. #region Loop to Create Share 
  134. $body = @" 
  135. The File Cluster Migration script Share Creation Routine has Started.  
  136. "@ 
  137. $subject = "FCMigration Script Share Creation Routine has Started." 
  138. $smtp = new-object Net.Mail.SmtpClient($smtpServer
  139. $smtp.Send($emailFrom, $emailTo, $subject, $body
  140. ## ===================================================================== 
  141. ## Loop to Create Share 
  142. ## ===================================================================== 
  143. Foreach ($UserName in (Get-Content $InputFile)) 
  144. $SharesCreated=$SharesCreated+
  145. $Sharename=$UserName+"$" 
  146. $RunNetCommand="cmd /c $NetPath$Sharename=$HomePath$UserName '/GRANT:EVERYONE,FULL'" 
  147. Invoke-Expression $RunNetCommand 
  148. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  149. Write-Host "��������������������������������������������������������������������������������"  -ForegroundColor Green 
  150. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  151. Write-Host "The Share Creation Routine Created" $SharesCreated "of" $Total "shares" -ForegroundColor Green 
  152. Write-Host "See the file at" $ShareReportPath "for details" -ForegroundColor Green 
  153. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  154.   $body = @" 
  155. The File Cluster Migration script Share Creation Routine Completed.  
  156. It processed $SharesCreated shares out of a possible $Total of users. 
  157. The log file of the shares created is located at $ShareReportPath." 
  158.  
  159. The Directory / File ownerhsip is being set.  
  160.  
  161. "@ 
  162. $subject = "FCMigration Script Share Creation Routine Completed." 
  163. $smtp = new-object Net.Mail.SmtpClient($smtpServer) 
  164. $smtp.Send($emailFrom, $emailTo, $subject, $body) 
  165. #endregion 
  166.  
  167. #region Loop to Grant Onwer of Home Directory 
  168. ## ===================================================================== 
  169. ## Loop to Grant Onwer of Home Directory 
  170. ## ===================================================================== 
  171. $RunIcaclsCommand="cmd /c $IcaclsPath$HomePath /setowner Administrators /T"  
  172. Invoke-Expression $RunIcaclsCommand 
  173. Foreach ($UserName in (Get-Content $InputFile)) 
  174. { 
  175. $HomeDirModified=$HomeDirModified+1 
  176. $RunIcaclsCommand="cmd /c $IcaclsPath$HomePath$UserName /setowner $UserName /T" 
  177. Invoke-Expression $RunIcaclsCommand 
  178. } 
  179. Write-Host "��������������������������������������������������������������������������������"  -ForegroundColor Green 
  180. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  181. Write-Host "The Grant Owner Routine Modified "$HomeDirModified" of " $Total "home folders" -ForegroundColor Green 
  182. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  183.   $body = @" 
  184. The File Cluster Migration script Grant Owner Routine Completed.  
  185. The Grant Owner Routine Modified " $HomeDirModified " home folders out of " $Total "home folders to modify 
  186.  
  187. The routine to un-compress the files and directories is being run.  
  188. "@ 
  189. $subject = "FCMigration Script Grant Ownership Completed." 
  190. $smtp = new-object Net.Mail.SmtpClient($smtpServer) 
  191. $smtp.Send($emailFrom, $emailTo, $subject, $body) 
  192. #endregion 
  193.  
  194. #region Invoke compress command to uncompress files 
  195. ## ===================================================================== 
  196. ## Invoke compress command to uncompress files 
  197. ## ===================================================================== 
  198. Write-Host "��������������������������������������������������������������������������������"  -ForegroundColor Green 
  199. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  200. Write-Host "The UnCompress Routine Has been started, This will take a while..." -ForegroundColor Green 
  201. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  202. $UserName=" " 
  203. Foreach ($UserName in (Get-Content $InputFile)) 
  204. { 
  205. $UserDir=$HomePath+$Username 
  206. $RunCompact="cmd /c compact /u /s:$UserDir /f /i /q" 
  207. Invoke-Expression $RunCompact 
  208. } 
  209. #endregion 
  210.  
  211. #region Send Completion Email 
  212. ## ===================================================================== 
  213. ## Send Completion Email 
  214. ## ===================================================================== 
  215. $body = @" 
  216. The File Cluster Migration script has completed.  
  217. It processed $SharesCreated shares out of a possible $Total of users. 
  218. The log file of the shares created is located at $ShareReportPath." 
  219.  
  220. and the Grant Owner Routine Modified $HomeDirModified home folders out of $Total home folders to modify. 
  221.  
  222. This email signifies the end of the un-compress routine, the script has completed and stopped.  
  223.  
  224. "
  225. $subject = "FCMigration Script Has Completed." 
  226. $smtp = new-object Net.Mail.SmtpClient($smtpServer
  227. $smtp.Send($emailFrom, $emailTo, $subject, $body
  228. Write-Host "��������������������������������������������������������������������������������"  -ForegroundColor Green 
  229. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  230. Write-Host "      F I L E  C L U S T E R  M I G R A T I O N  T O O L  C O M P L E T E" -ForegroundColor Green 
  231. Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta 
  232. Write-Host "��������������������������������������������������������������������������������"  -ForegroundColor Green 
  233. #endregion 
  234. Exit 
This script was designed to migrate from a Windows 2003 Cluster to Windows 2008 Cluster. The differences in how the two clusters work regarding shares caused us to manually create the shares and fix permissions on the 200 cluster. This script was written to facilitate the following functions read from a text file user IDs, create share with everyone full access from user IDs, grant first administrator then the user ownership if there directory. The script will send an email at the start of the script, and each task change then at the completion. This was a great time saver, by hand it took two of us 5 hours to create the shares manually, the script did it in about 15 -20 minutes. This has to be run on the 2008 cluster node with the resource it is creating shares for.
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.