Format Partition

This topic contains 10 replies, has 5 voices, and was last updated by Profile photo of Mr. Jacko Mr. Jacko 2 years, 4 months ago.

  • Author
    Posts
  • #17055
    Profile photo of Mr. Jacko
    Mr. Jacko
    Participant

    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

  • #17056
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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:""
    
    • #17057
      Profile photo of Mr. Jacko
      Mr. Jacko
      Participant

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

  • #17058
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    Win32_Volume has a format method that you could use – http://msdn.microsoft.com/en-us/library/aa394515%28v=vs.85%29.aspx

    • #17063
      Profile photo of Mr. Jacko
      Mr. Jacko
      Participant

      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
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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
      Profile photo of Mr. Jacko
      Mr. Jacko
      Participant

      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
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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
    Profile photo of Sam Boutros
    Sam Boutros
    Participant

    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
            }
    
  • #17088
    Profile photo of Mr. Jacko
    Mr. Jacko
    Participant

    Thanks for your valuable suggestions

You must be logged in to reply to this topic.