• windows server更改盘符


    使用powershell更改盘符

    echo `n
    Write-host "Display existing driveLetter partition" -ForegroundColor Green
    Get-Volume
    
    echo `n
    
    function getvolume
    {
        
        $volume_a = Get-Volume | Select-Object -Property DriveLetter,DriveType
        $hashTablea = @{}
        foreach($volumeInfoa in $volume_a)
        {
            if ($volumeInfoa.DriveType -eq "Removable" -or $volumeInfoa.DriveType -eq "CD-ROM") 
            {
                $hashTablea.Add($volumeInfoa.DriveType,$volumeInfoa.DriveLetter)
            }
        }
    
        $hashTablea."CD-ROM"
        $hashTablea."Removable"
    
    }
    
    $cdname, $medianame = getvolume
    
    $volumeInfos=Get-WmiObject -Class win32_volume
    $hashTable = @{}
    $nu = $null
    
    foreach($volumeInfo in $volumeInfos)
    {
    
        if ( $volumeInfo.DriveType -eq 2 ) 
        {
            $mdl = $volumeInfo.DriveLetter
            $mdl = $mdl.Split(":")[0]
            $medianum = $volumeInfo.DriveType
    
            if ( $mdl -eq $medianame )
            {
                 Write-host "Modify CD-ROM drive letter to F" -ForegroundColor Green
                 Get-WmiObject -Class win32_volume -Filter "drivetype=$medianum" | Select-Object -First 1 | Set-WmiInstance -Arguments @{DriveLetter='G:'}
            }
        }
        
        echo `n
    
        if ( $volumeInfo.DriveType -eq 5 ) 
        {
            $cdl = $volumeInfo.DriveLetter
            $cdl = $cdl.Split(":")[0]
            $cdnum = $volumeInfo.DriveType
    
            if ( $cdl -eq $cdname )
            { 
                Write-host "Modify the Removable drive letter to G" -ForegroundColor Green
                Get-WmiObject -Class win32_volume -Filter "drivetype=$cdnum" | Select-Object -First 1 | Set-WmiInstance -Arguments @{DriveLetter='H:'}
            }
        }
    
    }
    
    echo `n
    Write-host "Display the changed drive letter" -ForegroundColor Green
    Get-Volume
    echo `n
    
    sleep 10
  • 相关阅读:
    读后感四
    读后感五
    公文流转系统
    统计文件中单词的频率,给出前N的单词
    读入一个文件输出每个字母的频率
    小工到专家
    从小工到专家读后感
    动手动脑 类与对象
    海芋
    棕竹
  • 原文地址:https://www.cnblogs.com/hanshanxiaoheshang/p/15710848.html
Copyright © 2020-2023  润新知