Public/Set-WinDriveLabel.ps1

Function Set-WinDriveLabel{
    <#
        .SYNOPSIS
        Change windows drive label
 
        .DESCRIPTION
        This function can change drive letter of windows partitions.
        If do not define computer name, localhost will be choose as a target computer
 
        .EXAMPLE
        PS> Set-WinDriveLabel -ComputerName PC-01 -DriveLetter C -Label "OS"
 
        Volume label of drive C: was changed to [OS]
    #>

    [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='High')]
    Param (

        [string]$ComputerName = $null,

        [Parameter(Mandatory = $true)]
        [ValidateSet('C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')]
        [string]$DriveLetter,

        [Parameter(Mandatory = $true)]
        [string]$Label
    )

    begin{
        $filter = "DriveLetter = '"+ $DriveLetter + ":'"
        if ([string]::IsNullOrEmpty($ComputerName)){
            $ComputerName = $env:COMPUTERNAME
        }
    }
    process{
        Write-Verbose -Message "Geting target drive object ..."
        $drive = Get-CimInstance -ComputerName $ComputerName win32_volume -Filter $filter

        if($PSCmdlet.ShouldProcess( "Volume " + $DriveLetter + ":\", "Change Drive Label" + $srcFolder.Name)){
            $drive | Set-CimInstance -ComputerName $ComputerName -Property @{Label=$Label}
            Write-Output ("Volume label of drive {0}: was changed to [{1}]" -f  $DriveLetter, $Label )
        }
    }
}