03-14-2010
Downloads: 349
File size: 11.7kB
Views: 1,772
Embed
 |
FCMigrationPub.ps1 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Clear-Host
-
-
-
- $HomePath="N:\HomeDirs\"
- $InputFile="D:\HomeDirs.txt"
- $ShareReportPath="D:\Shares.log"
- $emailFrom = "FileClusterMigration@company.com"
- $emailTo = "superadmin@company.com,admin@company.com"
- $smtpServer = "smtp.company.com"
-
-
-
-
- $NetPath="C:\Windows\System32\NET.exe SHARE "
- $IcaclsPath="C:\Windows\System32\ICACLS.exe "
- $subject = ""
- $body = ""
- $RunCompact=""
- $Sharename=$UserName+"$"
- $SharesCreated=0
- $HomeDirModified=0
- $DirExists=0
- $DirNoExists=0
-
-
-
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- 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
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
-
-
-
-
-
-
-
- $body = @"
- The File Cluster Migration script count and verify directory has started.
- "@
- $subject = "FCMigration Script Count and Directory Verification Routine Started."
- $smtp = new-object Net.Mail.SmtpClient($smtpServer)
- $smtp.Send($emailFrom, $emailTo, $subject, $body)
-
- Foreach ($UserName in (Get-Content $InputFile))
- {
- $Count=$Count+1
- $Total=$Count
- $UserDir=$HomePath+$Username
-
- if (Test-Path $UserDir)
- {
- $DirExists=$DirExists+1
- }
- else
- {
- $DirNoExists=$DirNoExists+1
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- Write-Host "The Following Directories do not match the supplied User ID" -ForegroundColor Yellow
- Write-Host " "
- Write-Host "$UserDir, Does Not Exist for User ID: $UserName" -ForegroundColor Red
- Write-Host " "
-
-
- }
- }
- Write-Host "��������������������������������������������������������������������������������" -ForegroundColor Green
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- Write-Host " Total Directories Excpected - " $Total -ForegroundColor Green
- Write-host " Total Directories Found - " $DirExists -ForegroundColor Green
- Write-host " Total Directories Missing - " $DirNoExists -ForegroundColor Red
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
-
- If ($DirNoExists -gt 0)
- {
- Write-Host "��������������������������������������������������������������������������������" -ForegroundColor Red
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- Write-Host " FIX THE ABOVE ERRORS AND RE-RUN THIS SCRIPT!" -ForegroundColor Yellow
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
-
- Exit
- }
- Else
- {
-
- }
-
-
-
- $body = @"
- The File Cluster Migration script Share Creation Routine has Started.
- "@
- $subject = "FCMigration Script Share Creation Routine has Started."
- $smtp = new-object Net.Mail.SmtpClient($smtpServer)
- $smtp.Send($emailFrom, $emailTo, $subject, $body)
-
-
-
- Foreach ($UserName in (Get-Content $InputFile))
- {
- $SharesCreated=$SharesCreated+1
- $Sharename=$UserName+"$"
- $RunNetCommand="cmd /c $NetPath$Sharename=$HomePath$UserName '/GRANT:EVERYONE,FULL'"
- Invoke-Expression $RunNetCommand
- }
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- Write-Host "��������������������������������������������������������������������������������" -ForegroundColor Green
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- Write-Host "The Share Creation Routine Created" $SharesCreated "of" $Total "shares" -ForegroundColor Green
- Write-Host "See the file at" $ShareReportPath "for details" -ForegroundColor Green
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- $body = @"
- The File Cluster Migration script Share Creation Routine Completed.
- It processed $SharesCreated shares out of a possible $Total of users.
- The log file of the shares created is located at $ShareReportPath."
-
- The Directory / File ownerhsip is being set.
-
- "@
- $subject = "FCMigration Script Share Creation Routine Completed."
- $smtp = new-object Net.Mail.SmtpClient($smtpServer)
- $smtp.Send($emailFrom, $emailTo, $subject, $body)
- #endregion
-
- #region Loop to Grant Onwer of Home Directory
- ## =====================================================================
- ## Loop to Grant Onwer of Home Directory
- ## =====================================================================
- $RunIcaclsCommand="cmd /c $IcaclsPath$HomePath /setowner Administrators /T"
- Invoke-Expression $RunIcaclsCommand
- Foreach ($UserName in (Get-Content $InputFile))
- {
- $HomeDirModified=$HomeDirModified+1
- $RunIcaclsCommand="cmd /c $IcaclsPath$HomePath$UserName /setowner $UserName /T"
- Invoke-Expression $RunIcaclsCommand
- }
- Write-Host "��������������������������������������������������������������������������������" -ForegroundColor Green
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- Write-Host "The Grant Owner Routine Modified "$HomeDirModified" of " $Total "home folders" -ForegroundColor Green
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- $body = @"
- The File Cluster Migration script Grant Owner Routine Completed.
- The Grant Owner Routine Modified " $HomeDirModified " home folders out of " $Total "home folders to modify
-
- The routine to un-compress the files and directories is being run.
- "@
- $subject = "FCMigration Script Grant Ownership Completed."
- $smtp = new-object Net.Mail.SmtpClient($smtpServer)
- $smtp.Send($emailFrom, $emailTo, $subject, $body)
- #endregion
-
- #region Invoke compress command to uncompress files
- ## =====================================================================
- ## Invoke compress command to uncompress files
- ## =====================================================================
- Write-Host "��������������������������������������������������������������������������������" -ForegroundColor Green
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- Write-Host "The UnCompress Routine Has been started, This will take a while..." -ForegroundColor Green
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- $UserName=" "
- Foreach ($UserName in (Get-Content $InputFile))
- {
- $UserDir=$HomePath+$Username
- $RunCompact="cmd /c compact /u /s:$UserDir /f /i /q"
- Invoke-Expression $RunCompact
- }
- #endregion
-
- #region Send Completion Email
- ## =====================================================================
- ## Send Completion Email
- ## =====================================================================
- $body = @"
- The File Cluster Migration script has completed.
- It processed $SharesCreated shares out of a possible $Total of users.
- The log file of the shares created is located at $ShareReportPath."
-
- and the Grant Owner Routine Modified $HomeDirModified home folders out of $Total home folders to modify.
-
- This email signifies the end of the un-compress routine, the script has completed and stopped.
-
- "@
- $subject = "FCMigration Script Has Completed."
- $smtp = new-object Net.Mail.SmtpClient($smtpServer)
- $smtp.Send($emailFrom, $emailTo, $subject, $body)
- Write-Host "��������������������������������������������������������������������������������" -ForegroundColor Green
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- 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
- Write-Host "--------------------------------------------------------------------------------" -ForegroundColor Magenta
- Write-Host "��������������������������������������������������������������������������������" -ForegroundColor Green
-
- 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.