locked
Format a RAW disk and Assign a drive letter from user input RRS feed

  • Question

  • Hello Guys

    the below script is to format a raw disk and assign a drive letter from user input based on the drive size.

    the script is not working at new-partition, please help.

     

    $rawdisks = (Get-Disk | where {$_.PartitionStyle -eq 'raw'})
    foreach( $rawdisk in $rawdisks)
    {
    $rawdisksize = $rawdisk.size/1GB
    $disknumber = $rawdisk.Number
    
    Write-Host "Enter a Drive letter for the  Disk size =  $rawdisksize GB" -ForegroundColor Magenta
    
    $letterassign = Read-Host ":"
    
    $rawdisk|Initialize-Disk -PartitionStyle MBR -PassThru
    
    New-Partition -DiskNumber $disknumber -AssignDriveLetter -DriveLetter $letterassign -UseMaximumSize 
    
    Format-Volume -DriveLetter $letterassign -FileSystem NTFS -Confirm:$false
    
    }
    

    Regards

    JITHIN.R


    JITHIN.R

    Friday, December 28, 2018 11:39 AM

Answers

  • Hi issue is solved.

    I have modified the script.

    $rawdisks = (Get-Disk | where {$_.PartitionStyle -eq 'raw'})
    foreach( $rawdisk in $rawdisks)
    {
    $rawdisksize = $rawdisk.size/1GB
    $disknumber = $rawdisk.Number
    
    Write-Host "Enter a Drive letter for the  Disk size =  $rawdisksize GB" -ForegroundColor Magenta
    
    $letterassign = Read-Host ":"
    
    $rawdisk|Initialize-Disk -PartitionStyle MBR -PassThru | 
    New-Partition -AssignDriveLetter -UseMaximumSize |
    
    Format-Volume -FileSystem NTFS -Confirm:$false
    
    get-partition -disknumber $disknumber | set-partition -newdriveletter $letterassign
    
    }



    JITHIN.R

    • Marked as answer by jrv Wednesday, January 2, 2019 2:45 AM
    Tuesday, January 1, 2019 6:41 AM

All replies

  • What does "not working" mean?


    \_(ツ)_/

    Friday, December 28, 2018 11:55 AM
  • the purpose the script is to identify the raw disk format with ntfs and assign a drive letter (a user input)

    -assign drive letter part is giving an error...


    JITHIN.R

    Friday, December 28, 2018 1:35 PM
  • -assign drive letter part is giving an error...

    Don't you think it would be helpful to know what error?

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, December 28, 2018 1:42 PM
  • sorry for the delayed response.

    please find the error code.

    https://drive.google.com/file/d/1snFBZZEJv65Rv5mOF9jfTjXoEAJ2VOBZ/view?usp=sharing 


    JITHIN.R

    Sunday, December 30, 2018 9:40 AM
  • An image of your code is not helpful  .... that's valid for error messages as well.  The post editor offers a code posting tool. Use it please.

    The error message is pretty obvious. One of the parameters you pass to New-Partition is invalid. Did you try to specify the parameters manually?


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Sunday, December 30, 2018 5:44 PM
  • Hi issue is solved.

    I have modified the script.

    $rawdisks = (Get-Disk | where {$_.PartitionStyle -eq 'raw'})
    foreach( $rawdisk in $rawdisks)
    {
    $rawdisksize = $rawdisk.size/1GB
    $disknumber = $rawdisk.Number
    
    Write-Host "Enter a Drive letter for the  Disk size =  $rawdisksize GB" -ForegroundColor Magenta
    
    $letterassign = Read-Host ":"
    
    $rawdisk|Initialize-Disk -PartitionStyle MBR -PassThru | 
    New-Partition -AssignDriveLetter -UseMaximumSize |
    
    Format-Volume -FileSystem NTFS -Confirm:$false
    
    get-partition -disknumber $disknumber | set-partition -newdriveletter $letterassign
    
    }



    JITHIN.R

    • Marked as answer by jrv Wednesday, January 2, 2019 2:45 AM
    Tuesday, January 1, 2019 6:41 AM
  • Input: "Format-Volume –DriveLetter G -FileSystem NTFS": replace G with a new drive letter you want to assign to your partition.

    If it fails again, try AOMEI Partition Assistant to format partition and assign drive letter

    Wednesday, January 2, 2019 2:42 AM