Author Posts

July 12, 2014 at 2:58 pm

Hi,
I need to create a script that will format a partition that can be d:, e:, f: or g: (different from pc to pc ...).
I can not go on ..
help!
Thank you

July 12, 2014 at 3:15 pm

If you're running Windows 8 or later, there's a PowerShell cmdlet called Format-Volume. Otherwise, you can use good old format.com; it still works, even on Windows 8.

As for how you figure out which volume to format, we'd need more information there (and that's probably the "script" part of your question.) Once you know the letter, though, you can just do something like this:

$volume = 'f:'
format $volume /Q /V:""

July 12, 2014 at 3:55 pm

I need for windows 7 and windows 8.
Format.com commad run on powershell script?
The partition to be formatted can assume different letters (d:, e:, f:, g:, ..). I need a script to format all partitions that it finds with the exception of C:
I hope I was clear ....

July 12, 2014 at 4:45 pm

I see. This is obviously a very destructive script, so test it at your own risk. Assuming that you only want to target local, fixed disks, you could do something like this:

Get-WmiObject Win32_LogicalDisk -Filter "DriveType = 3 AND DeviceID != '$env:SystemDrive'" |
ForEach-Object {
    format $_.DeviceID /Q /V:""
}

July 13, 2014 at 6:51 am

Ok, I'll try to use also Win32_Volume format method....
All I need this because I have to erase the data on the partitions of many pc that need to be scrapped.
Two questions:
1. You can also apply a secure erase?
2. You can format/erase, using the same method, the active partition (C :)?

July 13, 2014 at 7:34 am

Formatting a partition does not protect your data. You can download free tools to get data off a formatted drive. Through OS Depoyment, we've formatted drives, put a new OS on there and used utilities to pull data off. Depending on the kind of data being protected, the drives are usually pulled from the chassis and destroyed. All I'm eluding to is that formatting partitions is just giving a false sense of security. Security through obscurity.

July 13, 2014 at 7:41 am

In reality this is just a information is not strictly necessary ....
there are no sensitive data would be sufficient to delete/format the partitions.
You can also do this for the active partition (C :)?

July 13, 2014 at 10:38 am

No. You'd be in the OS running the command and trying to delete the OS. Assuming the command doesn't have a measure to not allow you to wipe the SYSTEM partition, it would start wiping the OS and probably blue screen. Typically, you would have a WinPE boot disk and boot to and then run the command since WinPE only exists in memory and you could wipe all disks. You can build a WinPE boot disk and add scripting support and inject the .BAT or PS1 that would wipe all partitions. You could also use DISKPART to clean and\or reformat the partitions.

July 13, 2014 at 11:05 am

I believe the last part of this script http://gallery.technet.microsoft.com/Powershell-script-to-e4df3bae does just that.
Basically you're looking at lines 79-83 of this script:

    $DriveLetter = "k"
    $BlockSize = 64KB
    #
    $VMDisks = Get-Disk | where partitionstyle -eq "Raw" # Get raw disks if any. You can change this line to pick a specific disk based on disk number for example like: Get-Disk | where Number -EQ 0
    if ($VMDisks.Count -gt 0) {
        Initialize-Disk -Number $VMDisks[0].Number -PartitionStyle GPT -PassThru 
        New-Partition -DiskNumber $VMDisks[0].Number -DriveLetter $DriveLetter -UseMaximumSize
        Format-Volume -DriveLetter $DriveLetter -FileSystem NTFS -NewFileSystemLabel "Drive_$DriveLetter" -Confirm:$false -AllocationUnitSize $BlockSize
        }

July 13, 2014 at 2:16 pm

Thanks for your valuable suggestions