Thicket data repository for the EEG
at main 4.1 kB view raw
1{ 2 "id": "https://www.tunbury.org/2019/01/17/mount-an-iso-from-your-desktop-via-powercli", 3 "title": "Mount an ISO from your Desktop via PowerCLI", 4 "link": "https://www.tunbury.org/2019/01/17/mount-an-iso-from-your-desktop-via-powercli/", 5 "updated": "2019-01-17T12:41:29", 6 "published": "2019-01-17T12:41:29", 7 "summary": "Normally, I’d used a Windows NFS Server to host my ISO files. The steps couldn’t be simpler", 8 "content": "<p>Normally, I’d used a Windows NFS Server to host my ISO files. The steps couldn’t be simpler</p>\n\n<div><div><pre><code>Add-WindowsFeature FS-NFS-Service\nNew-NfsShareimport\nImport-Module NFS\nNew-NfsShare -Name ISO -Path C:\\ISO -access readonly\n</code></pre></div></div>\n\n<p>However, this only works if you have a Windows Server installation as you can’t install the NFS Service on a Windows desktop.</p>\n\n<p>There is a standalone executable version of an NFS server available called WinNFSd.exe which can be downloaded from <a href=\"https://github.com/winnfsd/winnfsd/releases\">GitHub</a>. I’ve saved this to <code>C:\\WinNFSd</code></p>\n\n<p>Create a firewall rule on your desktop to allow the allow the ESXi host to communicate with WinNFSd, thus:</p>\n\n<div><div><pre><code>New-NetFirewallRule -DisplayName \"NFS Server\" -Direction Inbound -Action Allow -Program C:\\WinNFSd\\WinNFSd.exe\n</code></pre></div></div>\n\n<p>Run <code>WinNFSd</code>. The argument list is the local folder hosting your ISO files to be shared and the path that it will have on the NFS server’s export list. The path name needs to match the <code>New-DataStore</code> command later:</p>\n\n<div><div><pre><code>Start-Process C:\\WinNFSd\\WinNFSd.exe -ArgumentList \"C:\\ISO /ISO\"\n</code></pre></div></div>\n\n<p>You should now have a CMD window open along with the PowerCLI prompt.</p>\n\n<p>Now you need to know the IP Address of your machine:</p>\n\n<div><div><pre><code>$myIPAddress = \"Your IP Address\"\n</code></pre></div></div>\n\n<p>You can automate this as follows but this may need to be tweaked depending upon which network card you are using etc.</p>\n\n<div><div><pre><code>$myIPAddress = $(Get-NetIPAddress -InterfaceAlias Ethernet0 -AddressFamily IPv4).IPAddress\n</code></pre></div></div>\n\n<p>Create a variable for your ESXi host(s).</p>\n\n<div><div><pre><code>$esxHosts = @( \"Your Host\" )\n</code></pre></div></div>\n\n<p>If you have a cluster you can include them all like this:</p>\n\n<div><div><pre><code>$esxHosts = Get-Datacenter yourDC | Get-Cluster yourCluster | Get-VMHost\n</code></pre></div></div>\n\n<p>Instruct the ESXi host to mount the datastore. Note that the final <code>/ISO</code> needs to match the final argument to <code>WinNFSd</code></p>\n\n<div><div><pre><code>$esxHosts |% { New-Datastore -VMHost $_ -Name ISO -NfsHost $myIPAddress -Path /ISO }\n</code></pre></div></div>\n\n<p>Now set the ISO that you have, such as <code>c:\\iso\\myiso.iso</code> to be the CD Drive on your VM</p>\n\n<div><div><pre><code>Get-CDDrive $vm | Set-CDDrive -IsoPath \"[ISO] myiso.iso\" -Connected:$true -Confirm:$false\n</code></pre></div></div>\n\n<p>Now you can use the CD Drive in the VM as you wish.</p>\n\n<p>Of course, it’s important tidy up in the correct sequence. Don’t just close the CMD prompt before disconnecting the CD drive and unmounting the datastore.</p>\n\n<p>Disconnect the CD Drive</p>\n\n<div><div><pre><code>Get-CDDrive $vm | Set-CDDrive -NoMedia -Confirm:$false\n</code></pre></div></div>\n\n<p>Remove the datastore</p>\n\n<div><div><pre><code>$esxHosts |% { Remove-Datastore -VMHost $_ -Datastore ISO -Confirm:$false }\n</code></pre></div></div>\n\n<p>Stop WinNFSd and remove the firewall rule</p>\n\n<div><div><pre><code>Stop-Process -Name WinNFSd\nRemove-NetFirewallRule -DisplayName \"NFS Server\"\n</code></pre></div></div>", 9 "content_type": "html", 10 "author": { 11 "name": "Mark Elvers", 12 "email": "mark.elvers@tunbury.org", 13 "uri": null 14 }, 15 "categories": [ 16 "powershell" 17 ], 18 "source": "https://www.tunbury.org/atom.xml" 19}