Format Partition

This topic contains 10 replies, has 5 voices, and was last updated by  Mr. Jacko 3 years, 10 months ago.

  • Author
  • #17055

    Mr. Jacko

    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 ..
    Thank you

  • #17056

    Dave Wyatt

    If you're running Windows 8 or later, there's a PowerShell cmdlet called Format-Volume. Otherwise, you can use good old; 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:""
    • #17057

      Mr. Jacko

      I need for windows 7 and windows 8. 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 ....

  • #17058

    Dave Wyatt

    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:""
  • #17059

    Richard Siddaway

    Win32_Volume has a format method that you could use –

    • #17063

      Mr. Jacko

      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 :)?

  • #17069

    Rob Simmers

    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.

    • #17071

      Mr. Jacko

      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 :)?

  • #17081

    Rob Simmers

    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.

  • #17084

    Sam Boutros

    I believe the last part of this script 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
  • #17088

    Mr. Jacko

    Thanks for your valuable suggestions

You must be logged in to reply to this topic.