How to mount and unmount ISO or IMG in Windows

Windows 8 or 10

Since Windows 8, there has been support in the OS for mounting an ISO or IMG file to a drive letter.

  • To mount, open Powershell and use Mount-DiskImage command:
$ Mount-DiskImage -ImagePath C:\MyFiles\foo.iso

Remember that you need to provide the full path to the file. The file will be mounted on the lowest available drive letter.

  • To unmount, open a command prompt with administrator privileges and use the mountvol command:
$ mountvol F: /d

Windows 7 and older

Windows 7 and older versions of Windows do not have internal support for mounting ISO or IMG file. Use the Virtual CloneDrive tool as described here to mount and unmount.

Delete pages from a DjVu document

Deleting one or more pages from a DjVu document can be done using the DjVuΒ multipage document manipulation utility. This is the executable djvm.exe that ships with the DjVuLibre package.

The -d option can be used to delete a single page from the document. However, djvm does not accept multiple pages or a range of pages to delete. To achieve this, invoke djvm multiple times using the looping features of your shell. The example below is for PowerShell.

Tried with: DjVuLibre 3.5.25.3

Run an executable whose path has spaces in PowerShell

Running an executable from a directory whose path has spaces in it is not straightforward in PowerShell.

For example, the command below will not work since PowerShell thinks that it is a string because it is quoted:

$ "C:\Program Files (x86)\DjVuZone\DjVuLibre\djvm.exe"

To run this executable, PowerShell needs to be instructed explicitly to execute the string that it is given. This is done using the function call operator (&):

$ & "C:\Program Files (x86)\DjVuZone\DjVuLibre\djvm.exe"

Tried with: PowerShell 2.0

How to find the version of your PowerShell

How do you find out the version of PowerShell you are using? This information can be found from the PSVersionTable variable. It holds the versions of the various components of PowerShell.

$ $PSVersionTable
Name                           Value
----                           -----
CLRVersion                     2.0.50727.5448
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

To find just the version of the shell component:

$ $PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1

So, I am using version 2.0 πŸ™‚

Tried with: PowerShell 2.0

PowerShell: Find the type of objects

The biggest selling point of PowerShell is that it deals with objects instead of mere strings. When putting the pieces of a command pipeline together, one wonders what is the type of objects coming down the pipeline. Finding this out is easy: pipe the output objects to a ForEach-Object loop and print the type of each object.

For example, the type of objects from a text file:

$ Get-Content Foo.txt | ForEach-Object { $_.GetType().FullName }
System.String
System.String
...

Another example, to find the type of objects from a string find:

$ Get-Content Foo.txt | Select-String "blah" | ForEach-Object { $_.GetType().FullName }
Microsoft.PowerShell.Commands.MatchInfo
Microsoft.PowerShell.Commands.MatchInfo
...

Tried with: PowerShell 2.0

PowerShell: Out-File versus Set-Content

If you want to pipe some content to a file, which of these two cmdlets would you use: Out-File or Set-Content?

Out-File is just the same as the output redirection operator (>) you use in any other shell. It formats the output as if it were writing to the console and instead of writing to the console, it writes to the file you specify.

This behaviour of Out-File can be sometimes problematic. If the content you are piping through Out-File has lines of text that are longer than the console width, Out-File will break them at the console width into a newline. So, you might end up with files where the long input lines have been broken down into multiple smaller lines of length equal to the console width.

If you do not want such meddling in your content, stick to using Set-Content to pipe output to files. Set-Content does not mess with the content and writes the textual content pristinely to file.

Tried with: PowerShell 2.0

PowerShell: Output Redirection Operators

The output redirection operators > and >> work in PowerShell just like they do in any other shell. > overwrites a file while >> appends to the file.

These output redirection operators are just aliases for the Out-File cmdlet. The equivalent invocations for > and >> are Out-File and Out-File -Append

Tried with: PowerShell 2.0

PowerShell: Viewing Environment Variables

In the Windows command prompt, environment variables could be viewed by using the set command. In PowerShell, all the environment variables are available on a PowerShell drive named Env:

To list all the environment variables and their values:

$ Get-ChildItem Env:
$ dir Env:

To display the value of a specific environment variable, for example the PATH environment variable:

$ $Env:PATH

Tried with: PowerShell 2.0