Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############################################################
- ############################################################
- ### The following script is called from Scheduled task with the action "provision-storage-2016.ps1 cluster01.blah.com"
- ############################################################
- Start-Transcript -Append -Path e:\temp\transcript.txt
- # Import MySQL Driver and Connect to DB
- Import-Module -Name C:\windows\system32\WindowsPowerShell\v1.0\Modules\MySQL\MySql.Data.dll
- $ConnectionString = “Server=localhost;uid=blah; pwd=blah;Database=database;”
- $MySQLConnection = New-Object -TypeName MySql.Data.MySqlClient.MySqlConnection
- $MySQLConnection.ConnectionString = $ConnectionString
- $MySQLConnection.Open()
- # Grab most recent pending provision
- # Build Query
- $query = "SELECT * FROM table WHERE pending=1 ORDER BY date ASC LIMIT 0,1"
- # Execute Query
- $command = New-Object MySql.Data.MySqlClient.MySqlCommand($query, $MySQLConnection)
- $dataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($command)
- # Query to Array
- $table = new-object system.data.datatable
- $dataAdapter.Fill($table)
- # Execute the provision
- # Connect and Enter Remote Session Context
- $psuser = "domain\user"
- $pspassword = ConvertTo-SecureString "password" -AsPlainText -Force
- $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $psuser, $pspassword
- New-PSSession -ComputerName $args[0] -Credential $cred
- Enter-PSSession -ComputerName $args[0]
- $argumentlist = @($table.username),@($table.password),@($table.provisionstring),@($table.storagepool),@($table.sizeinbytes),@($table.clustergroup)
- $argumentlist | Out-File -Append -FilePath e:\temp\args.txt
- invoke-command -computername @($table.cluster) -FilePath "E:\provision-scripts\provision-smb3-share.ps1" -ArgumentList $argumentlist
- ############################################################
- ############################################################
- NOW THIS FILE IS THE PORTION THAT CREATES A MOUNTPOINT, CREATES AN NTFS VOLUME, AND ADDS THE RESOURCE TO THE "file server" cluster group
- ############################################################
- # Inputs
- param(
- [Parameter(Mandatory=$true,Position=1)]
- [string]$username,
- [Parameter(Mandatory=$true,Position=2)]
- [string]$randpass,
- [Parameter(Mandatory=$true,Position=3)]
- [string]$provisionstring,
- [Parameter(Mandatory=$true,Position=4)]
- [string]$storagepoolfriendlyname,
- [Parameter(Mandatory=$true,Position=5)]
- [string]$volumesizeinbytes,
- [Parameter(Mandatory=$true,Position=6)]
- [string]$clustergroup
- )
- # New User
- NET USER $username $randpass /ADD /DOMAIN /Y
- try{
- # New Directory to Mount New Volume to
- $mountpoint = "M:\" + $provisionstring
- New-Item -Path $mountpoint –ItemType Directory
- # New Volume
- new-volume -StoragePoolFriendlyName $storagepoolfriendlyname -friendlyname $provisionstring -FileSystem NTFS -ResiliencySettingName Parity -PhysicalDiskRedundancy 2 -ProvisioningType Fixed -Size $volumesizeinbytes -AccessPath $mountpoint -Verbose
- # Turn Off Maintenance Mode
- #resume-clusterresource -Name "Cluster Virtual Disk (" + $provisionstring + ")"
- # Attach Volume to File Server Role
- $fsrole = Get-ClusterGroup | Where { $_.Name -eq $clustergroup}
- #write-host "Cluster Group: " + $fsrole
- $clresource = Get-ClusterResource | where {$_.OwnerGroup -eq "Available Storage" -and $_.Name -eq "Cluster Virtual Disk (" + $provisionstring + ")"}
- #$clresource | Out-File -FilePath m:\provision\output.txt
- #write-host "Cluster Resource: " + $clresource
- Move-ClusterResource -Name $clresource -Group $fsrole
- # New SMB3 Share
- New-SmbShare -Name $provisionstring -Path $mountpoint -ScopeName $clustergroup -CachingMode None -ChangeAccess $username -ContinuouslyAvailable $true -Description $provisionstring -EncryptData $true -FolderEnumerationMode AccessBased -FullAccess "Domain Admins" -Confirm
- }
- Catch {
- #whatever
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement