Skip to content

Instantly share code, notes, and snippets.

@nanoDBA
Last active October 20, 2016 22:01
Show Gist options
  • Save nanoDBA/35c4922a10b7c46d320104cdfc1688a6 to your computer and use it in GitHub Desktop.
Save nanoDBA/35c4922a10b7c46d320104cdfc1688a6 to your computer and use it in GitHub Desktop.
## DANGER - this script is an example and will likely NUKE DELETE REMOVE DESTROY DATA
## If you run this on a prod system, it may be a résumé / CV generating event that could hurt businesses
###http://windowsitpro.com/windows-server-2012-r2/powershell-storage-space-creation-tips
#List all disks that can be pooled and output in table format (format-table)
Get-PhysicalDisk -CanPool $True | ft FriendlyName,OperationalStatus,Size,MediaType
get-disk 1,2
#### Initialize Disks to GPT
get-disk 1,2 | Initialize-Disk -PartitionStyle GPT
#Store all physical disks that can be pooled into a variable, $pd
$pd = Get-PhysicalDisk -CanPool $True
#Create a new Storage Pool using the disks in variable $pd with a name of Important Backups Storage Pool
New-StoragePool -PhysicalDisks $pd -StorageSubSystemFriendlyName "Storage Spaces*" -FriendlyName "Important Backups Storage Pool"
#View the disks in the Storage Pool just created
Get-StoragePool -FriendlyName "Important Backups Storage Pool" | Get-PhysicalDisk | Select FriendlyName, MediaType
New-VirtualDisk -StoragePoolFriendlyName "Important Backups Storage Pool" -ResiliencySettingName Simple -Size 1534464MB -Provisioningtype Thin -FriendlyName "Backups"
Get-StoragePool | format-table
Get-Volume | format-table
Get-Disk | format-table
Get-PhysicalDisk | format-table
get-disk 3 | Initialize-Disk -PartitionStyle GPT
get-disk 3 | New-Partition -UseMaximumSize -DriveLetter H
get-disk 3 | Format-Table
# https://blogs.msdn.microsoft.com/san/2012/07/03/managing-storage-with-windows-powershell-on-windows-server-2012/
Format-Volume -DriveLetter H -FileSystem NTFS -NewFileSystemLabel 'Important_BACKUPS' -AllocationUnitSize 64KB -Confirm:$false
H:
mkdir \ImportantBACKUP
#ACLs for filesystem - https://chrisfederico.wordpress.com/2008/02/01/setting-acl-on-a-file-or-directory-in-powershell/
$acl = Get-Acl H:\ImportantBACKUP
$permission = "DOMAINNAME\sql-service-account","FullControl","Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl H:\ImportantBACKUP
$acl = Get-Acl H:\ImportantBACKUP
$permission = "DOMAINNAME\DOMAINNAME\SQL-Group-DBAs","FullControl","Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl H:\ImportantBACKUP
#Create Share - http://windowsitpro.com/powershell/managing-file-shares-windows-powershell
New-SmbShare -Name ImportantBACKUP -Path H:\ImportantBACKUP -FullAccess "DOMAINNAME\SQL-Group-DBAs",DOMAINNAME\sql-service-account -Description ""
## DANGER
####NUKE DELETE REMOVE DESTROY DATA
# Cleanup
#Remove-SmbShare -Name ImportantBACKUP -Confirm:$false
#get-disk 3 | Clear-Disk -RemoveData -Confirm:$false
#Get-VirtualDisk -FriendlyName "Backups" | Remove-VirtualDisk -Confirm:$false
#Get-StoragePool -FriendlyName "Important Backups Storage Pool" | Remove-StoragePool -Confirm:$false
#get-disk 1,2 | Clear-Disk -RemoveData -Confirm:$false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment