locked
How to Dismiss a Format Request via PowerShell? RRS feed

  • Question

  • I've got a large PowerShell script that I run which configured multiple disks on new servers.  It's not too in depth, but is a summation of a bunch of information that I've accumulated over the years.  However, I'm still having one annoyance.  Since I call the New-Partition separately from the Format-Volume, I keep getting the lovely pop-up that states that You have a new disk and need to format it.


    Is there a way that I can dismiss this via PowerShell?  I'm sure I could find an errant process and kill that, but is there a better way?


    My PoSH Snippet:

    $DiskInfo  = @()
    $DiskInfo += New-Object -TypeName PSObject -Property ( [ordered]@{ DiskNumber = [int]1; DriveLetter = "D"; Label = "Page File" } )
    $DiskInfo += New-Object -TypeName PSObject -Property ( [ordered]@{ DiskNumber = [int]2; DriveLetter = "E"; Label = "Programs" } )
    $DiskInfo += New-Object -TypeName PSObject -Property ( [ordered]@{ DiskNumber = [int]3; DriveLetter = "F"; Label = "Web" } )
    $DiskInfo += New-Object -TypeName PSObject -Property ( [ordered]@{ DiskNumber = [int]4; DriveLetter = "G"; Label = "Logs" } )


    $FullFormat  = $true # indicates a "quick" format
    $UseLargeFRS = $true  # see https://technet.microsoft.com/en-us/library/dn466522(v=ws.11).aspx
    ForEach ( $Disk in $DiskInfo )
    {
        # Set Disk to Read-Write
        if ( Get-Disk -Number $Disk.DiskNumber | Where-Object { $_.IsReadOnly } )
        {
            Write-Host "Setting $( $Disk.DiskNumber ) to Read-Write"
            Get-Disk -Number $Disk.DiskNumber | Set-Disk -IsReadOnly:$false
        }
       
        # Create Partition and then Format it
        Write-Host "Creating partition on Disk $( $Disk.DiskNumber ) with Letter $( $Disk.DriveLetter ):"
        New-Partition -DiskNumber $Disk.DiskNumber -UseMaximumSize -DriveLetter $Disk.DriveLetter | Out-Null
        Write-Host "Formatting $( $Disk.DriveLetter ): [$( $Disk.Label )]"
        Format-Volume -DriveLetter $Disk.DriveLetter -FileSystem NTFS -AllocationUnitSize 64KB -Force -Confirm:$false -Full:$FullFormat -NewFileSystemLabel $Disk.Label
    }

    Monday, February 12, 2018 11:07 PM

All replies

  • Hi,

    Based on my research, the workaround solution of this behavior is to temporarily stop the "Shell Hardware Detection" Service, please have a try to add Stop-Service -Name ShellHWDetection at the beginning of the script and add Start-Service -Name ShellHWDetection to the end of the script.

    If you need further help, please feel free to let us know.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, February 13, 2018 4:54 AM
  • Hi,

    Just want to confirm the current situations. Have you tried the method provided before?

    If you already tried them or the issue remains after trying them, please don’t hesitate to tell me. I will do more research and try my best to give you helpful suggestions.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, February 15, 2018 4:18 AM
  • Hi,

    I am checking how the issue is going, if you still have any questions, please feel free to contact us.

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.

    Appreciate for your feedback.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, February 19, 2018 1:44 PM