Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

how do you select and format all removable drives to ntfs on windows 10 with powershell

  1. User

    how do you select and format all removable drives to ntfs on windows 10 with powershell

  2. Assistant

    To select and format all removable drives to NTFS using PowerShell in Windows 10, you can use the following steps:

    1. Open PowerShell: Press Win + X and select "Windows PowerShell (Admin)" from the context menu to open an elevated PowerShell window.

    2. List all removable drives: Execute the command Get-Disk | Where-Object { $_.IsRemovable }.

    3. Select the removable drives: Execute the command Get-Disk | Where-Object { $_.IsRemovable } | Select-Object Number.

    4. Initialize the disks: Execute the command Get-Disk | Where-Object { $_.IsRemovable } | Initialize-Disk -PartitionStyle MBR -PassThru.

      • If there is a GPT partition style, change -PartitionStyle MBR to -PartitionStyle GPT.
    5. Create a partition: Execute the command New-Partition -DiskNumber <Number> -UseMaximumSize | Format-Volume -FileSystem NTFS -Confirm:$false.

      • Replace <Number> with the DiskNumber value obtained from step 3. For example, DiskNumber 1.
    6. Repeat steps 5 for each removable disk you wish to format.

    7. Close PowerShell: Execute the command Exit.

    Please note that formatting a drive will erase all existing data on it, so make sure to backup any important data before proceeding.

    Also, exercise caution when working with disk management tasks to avoid accidentally formatting the wrong drives.

  3. User

    give me a full script to do this

  4. Assistant

    Certainly! Here's a full script that you can use to select and format all removable drives to NTFS using PowerShell in Windows 10:

    # Run PowerShell as Administrator
    
    # Step 1: List all removable drives
    $removableDrives = Get-Disk | Where-Object { $_.IsRemovable }
    
    foreach ($drive in $removableDrives) {
        # Step 2: Initialize the disk
        Initialize-Disk -Number $drive.Number -PartitionStyle MBR -Confirm:$false
    
        # Step 3: Create a partition and format to NTFS
        $partition = New-Partition -DiskNumber $drive.Number -UseMaximumSize
        $volume = Format-Volume -Partition $partition -FileSystem NTFS -Confirm:$false
        
        if ($volume) {
            Write-Host "Removable Drive $($drive.Number) successfully formatted to NTFS." -ForegroundColor Green
        }
        else {
            Write-Host "Failed to format Removable Drive $($drive.Number)." -ForegroundColor Red
        }
    }
    
    # Close PowerShell
    Exit
    

    Please ensure that you run this script with administrator privileges. It will go through each removable drive, initialize it, create a partition, and format it to NTFS. It will then display a success message or a failure message for each drive.

    Remember to backup any important data before running this script because formatting a drive will erase all existing data.