Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

IT-Wiki

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View my Codeberg Page

View my Photo Website

CD-Rom ändern

published: June 27, 2016 author: Tinu tags: Devices categories: PowerShell


CD-Rom auf anderen Laufwerksbuchstaben ändern.

function Get-CDRomLetter{
    $function = $($MyInvocation.MyCommand.Name)
    $ret = $null
    try
    {
        $ret = (gwmi Win32_cdromdrive).drive
    }
    catch [Exception]
    {
        write-host "$($function): $($_.Exception.Message)" -ForegroundColor Red
        $error.clear()
    }
    return $ret
}

function Set-CDRomLetter{
    param(
        [Parameter(Mandatory=$true)][String]$newdrive=''
    )
    $function = $($MyInvocation.MyCommand.Name)
    $ret = $null
    try
    {
        (gwmi Win32_cdromdrive).drive | %{
            #Lists the mounted volume name for the specified directory.
            $currentdrive = mountvol $_ /l
            #Removes the volume mount point from the specified directory.
            mountvol $_ /d
            $currentdrive = $currentdrive.Trim()
            mountvol $newdrive $currentdrive
        }
    }
    catch [Exception]
    {
        write-host "$($function): $($_.Exception.Message)" -ForegroundColor Red
        $error.clear()
    }
}

if (Get-CDRomLetter -notlike 'Z:')
{
    Set-CDRomLetter -newdrive 'Z:'
}

← Previous Post ◇ [ Top ] ◇ Copyright © 2024 by tinuwalther ◇ [ Blog ] ◇ Next Post →