WindowsServer

Powershell – How to format all disks

Did you know that you can manage disks, partitions and volumes using Powershell? Microsoft released a lot of cmdlet in order to facilitate handling of disks.

With virtualization, you can easily add disk to your server, but you have to create the volume yourself. I wrote a script that you can integrate in your process, runbooks or others.

Disks initialization

First thing to do, is to prepare disks to host volume. We need to set disks online and to disable Read only.

try {
#Set all disks, except the first disk, to online and writable
Get-Disk | ?{$_.number -ne 0}| Set-Disk -IsOffline $False
Get-Disk | ?{$_.number -ne 0}| Set-Disk -isReadOnly $False
 
#Initialize all disks
Get-Disk | ?{$_.number -ne 0}| Initialize-Disk -PartitionStyle GPT
}catch{
Write-Host $_.Exception.Message
}

Volume

Once disks are ready, we need to create, and format volume.

try {
#Create Partition on all disk, auto assign letter and use maximum size
Get-Disk | ?{$_.number -ne 0}| New-Partition -AssignDriveLetter -UseMaximumSize
#Get all partitions and format them
Get-Disk | ?{$_.number -ne 0}| Get-Partition |?{$_.type -like "Basic"}| Format-Volume -Confirm:$false
}catch{
Write-Host $_.Exception.Message
}

Remote

If you want to execute these command on a remote host, it is possible. We will use the cmdlet Invoke-Command

try {
#Set all disks, except the first disk, to online and writable
Invoke-Command -ComputerName $lServerName -ScriptBlock {Get-Disk | ?{$_.number -ne 0}| Set-Disk -IsOffline $False}
Invoke-Command -ComputerName $lServerName -ScriptBlock {Get-Disk | ?{$_.number -ne 0}| Set-Disk -isReadOnly $False}
#Initialize all disks
Invoke-Command -ComputerName $lServerName -ScriptBlock {Get-Disk | ?{$_.number -ne 0}| Initialize-Disk -PartitionStyle GPT}
#Create Partition on all disk, auto assign letter and use maximum size
Invoke-Command -ComputerName $lServerName -ScriptBlock {Get-Disk | ?{$_.number -ne 0}| New-Partition -AssignDriveLetter -UseMaximumSize}
#Get all partitions and format them
Invoke-Command -ComputerName $lServerName -ScriptBlock {Get-Disk | ?{$_.number -ne 0}| Get-Partition |?{$_.type -like "Basic"}| Format-Volume -Confirm:$false }			
}catch{
Write-Host  $_.Exception.Message
}

More

You can get more information about Disk Management cmdlet here.

Share
SCCM

SCCM 2012 – Enable Free Space in Reports

With System Center Configuration Manager, you can retrieve a lot of information about your computers, specially the Hardware Inventory.  And with Reporting Service Point, you can display it easily via a web page.

However, if you would like to display the Free space on a drive, you can do this but it is not enabled.

By default, when you execute the report “Disk information for a specific computer – Logical disks“, you will get a blank information about Free Space:

SCCM Free Space BlankHardware Inventory

To enable this option, you need to change the Hardware Inventory:

  • In the Logical Disk classe, check the Free Space item.
    Hardware Inventory Free Space

After that, wait for the Machine Policy retrieval and at the next Hardware Inventory, you will get the information.

FreeSpace Enabled

 

More

You can get more information on Hardware Inventory here

Share