Guest User

Untitled

a guest
Oct 28th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. [CmdletBinding()]
  2. param(
  3.  
  4. [Parameter(Mandatory=$true)]
  5. [string]$DomainNetBIOSName,
  6.  
  7. [Parameter(Mandatory=$true)]
  8. [string]$DomainAdminUser,
  9.  
  10. [Parameter(Mandatory=$true)]
  11. [string]$DomainAdminPassword,
  12.  
  13. [Parameter(Mandatory=$true)]
  14. [string]$WSFCNode1NetBIOSName
  15. )
  16.  
  17.  
  18.  
  19. try {
  20. Start-Transcript -Path C:\cfn\log\Label-and-Format-drives.txt -Append
  21. $ErrorActionPreference = "Stop"
  22.  
  23. $DomainAdminFullUser = $DomainNetBIOSName + '\' + $DomainAdminUser
  24. $DomainAdminSecurePassword = ConvertTo-SecureString $DomainAdminPassword -AsPlainText -Force
  25. $DomainAdminCreds = New-Object System.Management.Automation.PSCredential($DomainAdminFullUser, $DomainAdminSecurePassword)
  26.  
  27. $LablenFormatPs={
  28.  
  29. function ChangeDriveLabel([string]$driveletter,[string]$newlabel )
  30. {
  31. $disk = Get-WmiObject -Class win32_volume -Filter "DriveLetter = '$driveletter'"
  32. Set-WmiInstance -input $disk -Arguments @{ Label="DBLOG1"}
  33. }
  34.  
  35. function FormatSQLDisk([string]$driveletter, [string]$drivelabel)
  36. {
  37. Format-Volume `
  38. -DriveLetter $driveletter `
  39. -NewFileSystemLabel $drivelabel `
  40. -FileSystem NTFS `
  41. -AllocationUnitSize 65536 –Force -Confirm:$false
  42. }
  43.  
  44. $ErrorActionPreference = "Stop"
  45. #Label the disks
  46. ChangeDriveLabel -driveletter 'd:' -newlabel 'DBDATA'
  47. ChangeDriveLabel -driveletter 'e:' -newlabel 'DBLOG'
  48. ChangeDriveLabel -driveletter 'f:' -newlabel 'DBTEMPDB'
  49.  
  50. #Format the disk
  51. FormatSQLDisk -driveletter 'D' -drivelabel 'DBDATA'
  52. FormatSQLDisk -driveletter 'E' -drivelabel 'DBLOG'
  53. FormatSQLDisk -driveletter 'F' -drivelabel 'DBTEMPDB'
  54. }
  55.  
  56. $serverInstance = $WSFCNode1NetBIOSName
  57. Invoke-Command -Scriptblock $LablenFormatPs -ComputerName $WSFCNode1NetBIOSName -Credential $DomainAdminCreds
  58.  
  59. }
  60. catch {
  61. $error[0]|format-list -force #print more detail reason for failure
  62. $_ | Write-AWSQuickStartException
  63. }
Add Comment
Please, Sign In to add comment