Author Posts

May 4, 2016 at 5:17 pm

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.

May 4, 2016 at 5:20 pm

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/

May 5, 2016 at 1:27 am

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

May 6, 2016 at 4:44 am

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. 🙂

May 7, 2016 at 5:40 am

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

May 7, 2016 at 12:24 pm

@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
    }
}

May 9, 2016 at 5:42 pm

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

January 7, 2017 at 11:34 pm

I've just published cCDROMdriveletter as a personal learning exercise in how to publish a custom DSC resource to the PSGallery.

It is a bit over the top to have this in its own custom manifest, but that made it simpler and more self-contained. This is my first use of Appveyor too!

At some point, I'll learn enough Pester to write some unit tests, but I've tested it on a Win10 & 2012R2 boxes in the interim.

Feedback welcome via github.