How do you use DSC to [declaratively] change the drive letter of the CDROM?

This topic contains 6 replies, has 4 voices, and was last updated by Profile photo of Kiran Kiran 4 months, 2 weeks ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #38611
    Profile photo of Kiran
    Kiran
    Participant

    How do you use DSC to [declaratively] change the drive letter of the CDROM? I know how to use PowerShell to do this [imperatively]. I want the drive letter to be "i" on every server.

    #38612
    Profile photo of Will Anderson
    Will Anderson
    Keymaster

    Hey there Kiran. I haven't seen a DSC resource to change a CD-ROM drive, but you could always create a custom DSC resource. The easiest way to do it would be using the xDSCResourceDesigner module.

    I've actually got a walkthrough here if it helps. https://blogs.technet.microsoft.com/heyscriptingguy/2016/01/22/conceptualize-desired-state-configuration-part-6/

    #38616
    Profile photo of Arie H
    Arie H
    Participant

    The association of drive letters is in the registry, find the key and use the xRegistry resource.
    Other way would probably involve calling .net class directly from powershell, so you can use the Script built in resource and execute the drive-change-ps-script via the script resource

    #38677
    Profile photo of Will Anderson
    Will Anderson
    Keymaster

    You still have to configure Get, Set, and Test with the script resource though. If you're going to go that far, you might as well create the DSC resource so your configuration looks cleaner. Auditors and Managers find DSC Resource Providers less scary than code. 🙂

    #38711
    Profile photo of Kiran
    Kiran
    Participant

    You recommend I create a custom DSC resource even though I am using WMF 4?

    #38716
    Profile photo of Zuldan
    Zuldan
    Participant

    @kiran, here is a basic example for changing the CDROM drive letter using a script resource.

    Script ChangeCDROMDriveLetter 
    {
        GetScript = {
            @{
                GetScript = $GetScript
                SetScript = $SetScript
                TestScript = $TestScript
                Result = (Get-CimInstance -ClassName Win32_Volume -Filter "DriveLetter = 'D:'").DriveType -ne 5
            }           
        }
                
        SetScript = {
            Get-CimInstance -ClassName Win32_Volume -Filter "DriveLetter = 'D:'" | Set-CimInstance -Property @{ DriveLetter = "Z:" }
        }
    
        TestScript = {
            $Status = (Get-CimInstance -ClassName Win32_Volume -Filter "DriveLetter = 'D:'").DriveType -ne 5
            $Status -eq $True
        }
    }
    
    #38810
    Profile photo of Kiran
    Kiran
    Participant

    Edit: Thank you very much for everyone who responded. Zuldan really helped me!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.