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

**URL:** <https://forums.powershell.org/t/how-do-you-use-dsc-to-declaratively-change-the-drive-letter-of-the-cdrom/6371>\
**Category:** DSC\
**Created:** [May 4, 2016, 11:47am UTC](https://forums.powershell.org/t/how-do-you-use-dsc-to-declaratively-change-the-drive-letter-of-the-cdrom/6371 "2016-05-04T11:47:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiran1](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@kiran1](https://forums.powershell.org/u/kiran1)\
**Post date:** [May 4, 2016, 11:47am UTC](https://forums.powershell.org/t/how-do-you-use-dsc-to-declaratively-change-the-drive-letter-of-the-cdrom/6371/1 "2016-05-04T11:47:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![will-anderson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/will-anderson/32/234_2.png) [@will-anderson](https://forums.powershell.org/u/will-anderson)\
**Post date:** [May 4, 2016, 11:50am UTC](https://forums.powershell.org/t/how-do-you-use-dsc-to-declaratively-change-the-drive-letter-of-the-cdrom/6371/2 "2016-05-04T11:50:52Z")

</div>

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. [Conceptualize Desired State Configuration: Part 6 - Scripting Blog](https://blogs.technet.microsoft.com/heyscriptingguy/2016/01/22/conceptualize-desired-state-configuration-part-6/)

---

<div class="post-metadata">

**Author:** ![silent-steel](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@silent-steel](https://forums.powershell.org/u/silent-steel)\
**Post date:** [May 4, 2016, 7:57pm UTC](https://forums.powershell.org/t/how-do-you-use-dsc-to-declaratively-change-the-drive-letter-of-the-cdrom/6371/3 "2016-05-04T19:57:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![will-anderson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/will-anderson/32/234_2.png) [@will-anderson](https://forums.powershell.org/u/will-anderson)\
**Post date:** [May 5, 2016, 11:14pm UTC](https://forums.powershell.org/t/how-do-you-use-dsc-to-declaratively-change-the-drive-letter-of-the-cdrom/6371/4 "2016-05-05T23:14:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kiran1](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@kiran1](https://forums.powershell.org/u/kiran1)\
**Post date:** [May 7, 2016, 12:10am UTC](https://forums.powershell.org/t/how-do-you-use-dsc-to-declaratively-change-the-drive-letter-of-the-cdrom/6371/5 "2016-05-07T00:10:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gareth-shipp](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@gareth-shipp](https://forums.powershell.org/u/gareth-shipp)\
**Post date:** [May 7, 2016, 6:54am UTC](https://forums.powershell.org/t/how-do-you-use-dsc-to-declaratively-change-the-drive-letter-of-the-cdrom/6371/6 "2016-05-07T06:54:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kiran1](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@kiran1](https://forums.powershell.org/u/kiran1)\
**Post date:** [May 9, 2016, 12:12pm UTC](https://forums.powershell.org/t/how-do-you-use-dsc-to-declaratively-change-the-drive-letter-of-the-cdrom/6371/7 "2016-05-09T12:12:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kewalaka](https://avatars.discourse-cdn.com/v4/letter/k/7c8e57/32.png) [@kewalaka](https://forums.powershell.org/u/kewalaka)\
**Post date:** [January 7, 2017, 6:04pm UTC](https://forums.powershell.org/t/how-do-you-use-dsc-to-declaratively-change-the-drive-letter-of-the-cdrom/6371/8 "2017-01-07T18:04:50Z")

</div>

I’ve just published [cCDROMdriveletter](https://www.powershellgallery.com/packages/cCDROMdriveletter/1.1.0) 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](https://github.com/kewalaka/cCDROMdriveletter/).

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:16pm UTC](https://forums.powershell.org/t/how-do-you-use-dsc-to-declaratively-change-the-drive-letter-of-the-cdrom/6371/9 "2024-05-16T21:16:48Z")

</div>

Closed on May 16, 2024, 9:16pm UTC


