DPM CLI Tips ‘n Tricks: Powershell Basics

The scripts posted in this blog require knowledge of Powershell and DPM cmdlets. So we thought we would present some tips ‘n tricks to become power users!

 

Introduction

The first difference between any normal Command Line Interface (CLI) (typically, Windows cmd.exe based environment) & Powershell is that, Powershell is a full blown .Net environment and is object oriented. In other words, it treats all input/output parameters as objects and when you pipe one command to another, objects flow instead of plain text as in old shells. Similarly, DPM Management Shell also takes inputs in the form of objects – for example, DPM, Protection Group, Datasource, Library, Tape, Tape Drive, Disk etc. are all .Net objects. Let’s now move on to more interesting stuff.

 

Finding cmdLets (Get-Command or gcm)

For knowing all the cmdLets present in the Powershell instance, use Get-Command (or gcm in short). When run, the output will be something like this:

 

PS D:\ > Get-command

 

CommandType   Name                  Definition

———–       —-                   ———-

Cmdlet              Add-Content       Add-Content [-Path] <String[…

Cmdlet              Add-DPMDisk       Add-DPMDisk [-DPMDisk] <Disk…

Cmdlet              Add-History         Add-History [[-InputObject] …

Cmdlet              Add-Member        Add-Member [-MemberType]

Cmdlet              Add-PSSnapin      Add-PSSnapin [-Name] <String…

Cmdlet              Add-Tape            Add-Tape [-DPMLibrary] <Libr…

Cmdlet              Clear-Content      Clear-Content [-Path] <Strin…

 

Finding DPM cmdLets (Get-DPMCommand)

Similarly for getting all the cmdLets belonging to only DPM, use the Get-DPMCommand.

 

PS D:\ > Get-DPMCommand

 

CommandType  Name                      Definition

———–      —-                        ———-

Cmdlet            Add-DPMDisk             Add-DPMDisk [-DPMDisk] <Disk…

Cmdlet            Add-Tape                 Add-Tape [-DPMLibrary] <Libr…

Cmdlet            Connect-DPMServer   Connect-DPMServer [-DPMServe…

Cmdlet            Disable-DPMLibrary     Disable-DPMLibrary [-DPMLibr…

Cmdlet            Disable-TapeDrive      Disable-TapeDrive [-TapeDriv…

 

How to use a cmdlet?

 

1. Understanding the cmdlet parameters (Get-Command and Format-List)

There are two parts to understanding a cmdlet. First, to look at the various input parameters and various usages, you can use the Get-Command itself on a specific cmdlet, in the following fashion – Get-Command <cmdlet> | format-list (or gcm <cmdlet> | fl, in short).

 

PS C:\> gcm Set-Alias | fl

 

Name                     : Set-Alias

CommandType         : Cmdlet

Definition                : Set-Alias [-Name] <String> [-Value] <String> [-Description <String>] [-Option <ScopedItemOptions>] [-PassThru] [-Scope <String>] [-Force] [-Verbose] [-Debug] [-ErrorAction <ActionPreference>] [-ErrorVariable <String>] [-OutVariable <String>] [-OutBuffer <Int32>] [-WhatIf] [-Confirm]

 

 

2. Reading Help documentation for a cmdlet (Get-Help or help)

For reading the Help documentation for any cmdlet use the following (Get-Help or help)

 

Get-Help <cmdlet>

 

For example:

 

PS D:\ > Get-Help Add-Tape

 

NAME

    Add-Tape

 

SYNOPSIS

    Adds a tape to a DPM library.

 

 

SYNTAX

    Add-Tape [-DPMLibrary] <Library> [-Async] [-JobStateChangedEventHandler <Jo

    bStateChangedEventHandler>] [<CommonParameters>]

…..

 

3. Getting detailed help, and seeing sample scripts

For seeing additional information on each of the cmdLets, you can use the –Full or –Detailed parameters in Get-Help.

 

e.g.    Get-Help Add-Tape –Detailed

Get-Help Add-Tape –Full

 

DPM Object Properties (Get-Member or gm)

 

The DPM cmdlets are logically divided in three groups Protection (Backup), Recovery and Management related (Library & Disk). All the tasks that can be done from the DPM UI in these areas, can be done from the cmdLets in these areas. Infact, the CLI provides additional features than the UI, in some scenarios.

 

You can get the member properties of any object by pipelining the output to Get-Member:

 

For example:

 

$lib = Get-DPMLibrary -DPMServerName “Testing Server Name”

$lib | Get-Member

 

Will give all the members of $lib (Library object).

 

PS D:\ > $lib | get-member

 

TypeName: Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.LibraryMan

agement.Library

 

Name              MemberType    Definition

—-                ———-       ———

ClearCache       Method            System.Void ClearCache()

Dispose            Method            System.Void Dispose()

 

We hope this was useful, feel free to add comments as feedback to this post. And in the next version, we can add more tricks!

 

Mukul Shekawat, Balaji Hariharan