Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Copy and Mount a CD with PowerCLI

Posted on November 30, 2012

The other day I realized I needed to rebuild my SQL Server 2012 installation which I'm running on a virtual machine running on an ESX box. Given that I have PowerCLI and I like to do things from the command prompt when I can, I decided to mount the SQL Server 2012 ISO on the VM using PowerShell. This actually requires a few steps that I thought I would share.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

First, you naturally need to have PowerCLI installed. You will need to import the necessary snapins and connect to the ESX host.


Add-PSSnapin VMware.VimAutomation.core
Connect-viserver -Server ESX

Once connected, I can begin the process. Next, I need to copy the ISO file the datastore so that I can mount it from the VM. While the vmstore: PSDrive is fun to work with, you can't copy from the filesystem. Copying between providers is simply not allowed. Instead I'll use the Copy-DatastoreItem cmdlet. This will allow me to copy a local file to the VMware datastore.

The tricky part here is to get the right format for the datastore destination. This is where I want to copy to:


PS vmstore:\ha-datacenter\datastore3\ISO> dir

Datastore path: [datastore3] ISO

LastWriteTime Type Length Name
------------- ---- ------ ----
8/18/2009 9:09 AM IsoImageFile 2996799488 en_windows_server...

The "trick" is to grab the value for Datastore path from the directory listing. Thus, I can run this to copy the ISO file to the datastore.


$iso="C:\users\jeff\Downloads\en_sql_server_2012_standard_edition_with_sp1_x86_x64_dvd_1228143.iso"
$dest="vmstore:\ha-datacenter\datastore3\ISO"
Copy-DatastoreItem -Item $iso -Destination $dest -passthru

You get a nice progress bar and in a few minutes the file is copied. Now I can mount it in the VM's CDDrive using Set-CDDrive. The cmdlet will need a CDDrive object from a VM and the path to the ISO file. I'll have to construct a path using the VMware datastore format. It looks a little funny because it is not a typical Windows path.


$isopath = "[datastore3] ISO\en_sql_server_2012_standard_edition_with_sp1_x86_x64_dvd_1228143.iso"

For situations like this, I find it easiest to use the corresponding Get cmdlet, and pipe the resulting object to the Set cmdlet.


get-cddrive -VM "globomantics db" | set-cddrive -IsoPath $isopath -Connected $true

The only other parameter I specified was to connect the CDDrive to the VM. This command takes a moment to run and then in the VM I can "see" the DVD and use it normally. Awesome. When I'm finished I can dismount the CD much the same way.


get-cddrive -VM "globomantics db" | set-cddrive -NoMedia

This may seem like a lot of typing, but if it is something I need to do a lot I could build a simple script or function. And it is still faster (for me) than navigating the GUI.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

2 thoughts on “Copy and Mount a CD with PowerCLI”

  1. Pingback: Microsoft Most Valuable Professional (MVP) – Best Posts of the Week around Windows Server, Exchange, SystemCenter and more – #5 - TechCenter - Blog - TechCenter – Dell Community
  2. Pingback: Microsoft Most Valuable Professional (MVP) – Best Posts of the Week around Windows Server, Exchange, SystemCenter and more – #5 - Dell TechCenter - TechCenter - Dell Community

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d