windows 2012 powershell 4 and shadow copy disable RRS feed

  • Question

  • Hello:

            With diskPart you can disable shadow copy of any disk, for example:

    diskpart att vol clear shadowcopy

           So I need disable shadow copy over Disk 1 on a server windows 2012. The server have 2 disk:

    Number Friendly Name                            OperationalStatus
    ------ -------------                            -----------------
    1      VMware Virtual disk SCSI Disk Device     Online
    0      VMware Virtual disk SCSI Disk Device     Online

    But I need shadow copy on Disk 0, then only need disabled shadow copy on Disk 1.

    Any way to do this with powershell and without Diskpart??. Thanks and sorry for my bad english.

    Friday, January 9, 2015 4:41 PM


  • Hi Jandresaedo,

    I haven't found a powershell cmdlet can replace diskpart to do this, hwever, you can try to write a powershell function via diskpart like:

    param($setOrClear, $diskLabel)
    if( [string]::IsNullOrWhiteSpace($setOrClear) )
        $ScriptName = $MyInvocation.MyCommand.Name
        "usage: .\$ScriptName set   ""MY DISK LABEL"""
        "       .\$ScriptName clear ""MY DISK LABEL"""
    if( $setOrClear -ne "set" -and $setOrClear -ne "clear" )
        throw 'Valid actions are "set" and "clear"!'}
    if( [string]::IsNullOrWhiteSpace($diskLabel) )
        throw "Please specify a non-blank disk label!"}
    # Path of the temporary file to use as diskpart script
    $scriptFile = "$env:TMP\set-ntfs-ro-script.tmp"
    # Save "list volume" command to a temp-file
    "list volume" | Out-File -Encoding ascii $scriptFile
    # Execute diskpart providing the script, and select the involved line
    $matches = diskpart /s $scriptFile | Select-String $diskLabel
    if( $matches.Length -eq 0 )
        throw "No match for the label: $diskLabel"
    elseif ( $matches.Length -ge 2 )
        throw "More than one match for the label: $diskLabel"}
    # Obtain volume number
    $words = $matches.Line.Trim().Split(" ")
    if( !$words -or $words.Length -le 1 )
    {    throw "Volume number couldn't be obtained for the volume:`n$line"
    $volumeNum = $words.Get(1)
    # Save the command to modify read-only flag to a temp-file
    "select volume $volumeNum
    att vol $setOrClear shadowcopy
    detail vol" | Out-File -Encoding ascii $scriptFile
    # Execute the command, and print details
    diskpart /s $scriptFile
    # Clean the waste
    del $scriptFile

    Refer to:


    If there is anything else regarding this issue, please feel free to post back.

    Best Regards,

    Anna Wang

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com

    • Proposed as answer by AnnaWY Monday, January 19, 2015 5:37 AM
    • Marked as answer by AnnaWY Thursday, January 22, 2015 2:43 AM
    Thursday, January 15, 2015 5:17 AM