Windows PowerShell-based
management and scripting of IBM
storage
Utilizing the Windows Server 2012 Storage Management API for
PowerShell management of the IBM XIV, SAN Volume Controller and
Storwize family disk systems
Jeremy Canady
IBM Systems and Technology Group ISV Enablement
October 2013
© Copyright IBM Corporation, 2013
Table of contents
Abstract........................................................................................................................................1
Introduction .................................................................................................................................1
Guidance and assumptions .......................................................................................................1
Solution components .................................................................................................................2
Standards-based management background ........................................................................................... 2
Storage Management Initiative Specification (SMI-S)....................................................... 2
SMI-S provider................................................................................................................... 2
Windows Storage Management API (SMAPI) ......................................................................................... 2
PowerShell............................................................................................................................................... 3
Shell................................................................................................................................... 3
Cmdlets ............................................................................................................................. 3
.NET development............................................................................................................. 4
PowerShell scripts ............................................................................................................. 4
Modules and toolkits.......................................................................................................... 4
IBM storage interfaces ............................................................................................................................. 4
Solution requirements .............................................................................................................................. 4
Solution validation ......................................................................................................................4
SMAPI and PowerShell setup and configuration..................................................................................... 4
Connecting and querying storage system information ............................................................................ 5
Registering the SMI-S provider ......................................................................................... 5
Selecting the storage system ............................................................................................ 6
Populating the provider cache........................................................................................... 7
Query storage system information .................................................................................... 8
Selecting target ports from a specific host ....................................................................................... 9
Storage provisioning and management ................................................................................................... 9
Creating a new thick-provisioned volume ......................................................................... 9
Creating a new thin-provisioned volume ......................................................................... 10
Creating a masking set (also known as hosts)................................................................ 11
Mapping a volume to a host ............................................................................................ 12
Creating repeatable automation with scripts ......................................................................................... 13
PowerShell scripting overview......................................................................................... 13
Basic PowerShell script example .................................................................................... 13
Brining it all together, Provision-Storage cmdlet ............................................................. 14
Provision-Storage usage................................................................................................................ 15
Provision-Storage script detailed explanation................................................................................ 15
Provisioning-Storage complete script ............................................................................................ 20
Summary....................................................................................................................................22
Resources..................................................................................................................................23
Trademarks and special notices..............................................................................................24
Windows PowerShell-based management and scripting of IBM storage
Abstract
The purpose of this paper is to provide an introduction and demonstration on how Microsoft Windows
PowerShell, when combined with the Windows Storage Management API (SMAPI) included in
Windows Server 2012, might be levered to interactively administer and automate storage
management tasks on the IBM XIV Storage System, IBM System Storage SAN Volume Controller,
and IBM Storwize family disk systems.
Introduction
As enterprise IT infrastructure migrates to provide cloud-like functionality, administrators have begun using
tools and processes to address the new management paradigm presented by the cloud. Regardless of the
type of cloud deployment (public, private, or hybrid), the data generated and consumed continues to grow.
Effective cloud infrastructure management is predicated on successful storage management.
Microsoft® developed Windows Server 2012, in their words, as a “Cloud optimized OS”. Successful
storage management of both local and external storage was viewed as a key requirement for cloud
environments. Therefore, new features and functionality were added to Microsoft Windows® Server 2012.
Windows Server 2012 adopts a standards-based approach to storage management and extends this
standards-based approach to PowerShell, which is Microsoft’s task-based command-line shell and
scripting language designed for system administration.
IBM® is an active member in storage-based standard committees such as the Storage Networking
Industry Association (SNIA), and a participant in programs such as the Storage Management Initiative
Specification (SMI-S). IBM provides standards-compliant SMI-S interfaces on the IBM XIV® Storage
System, IBM System Storage® SAN Volume Controller (SVC), and IBM Storwize® disk family. Windows
Server 2012 uses these interfaces to provide local management of IBM storage systems.
This white paper provides details about how to configure Windows Server 2012 to connect to the IBM
Storwize V7000 SMI-S provider. It also demonstrates how common storage management tasks and
automation can be achieved with PowerShell.
Guidance and assumptions
The intent of this paper is to provide an introduction to the management of IBM storage systems with
Microsoft PowerShell and present use-case guidelines for customers who are planning, or have already
decided, to implement Windows Server 2012 with IBM XIV, IBM SAN Volume Controller, or IBM Storwize
family disk systems.
This paper provides a brief introduction to key components such as SMI-S, Common Information Model
(CIM), PowerShell, and Windows Server 2012 Storage Management API (SMAPI). It also provides
practical use cases for using these components for storage management and automation.
This paper is not intended to be a comprehensive PowerShell scripting guide for IBM storage. It also
assumes readers to have knowledge or familiarity in the following areas:
Windows Server 2012 operating system configuration and installation
Storage provisioning and management through standard interfaces
Creating, utilizing, or understanding common scripting languages
Familiarity with the Windows PowerShell environment
Windows PowerShell-based management and scripting of IBM storage
1
Solution components
The solution described in this white paper utilizes a standards-based management, SMAPI, and Windows
PowerShell. This section provides a background on these components.
Standards-based management background
Standards-based management focuses on reducing the complexity and effort to manage and automate a
diverse set of hardware and software. Standardizing on a defined specification and protocol allows system
manufactures to provide a common interface for administrators and software. The Distributed
Management Task Force (DMTF) is one of the key organizations guiding standards creation and
management. IBM is a leader of DMTF along with 16 other industry-leading technology companies.
DMTF provides a set of technology standards that is built upon each other to provide an end-to-end
management infrastructure. At the core is the CIM infrastructure and schema. CIM allows for the creation
of an object-oriented model of the managed element. DTMF then provides a Web Based Enterprise
Management (WBEM), which is a technology standard that allows management in distributed
environments. The combination of these technologies provides object-level management in a distributed
environment.
Many management initiatives such as Systems Management Architecture for Server Hardware (SMASH)
and SMI-S have been created to focus on specific application verticals. These initiatives provide a
standardized view of the specific application across diverse hardware.
Storage Management Initiative Specification (SMI-S)
SMI-S is an initiative created and managed by SNIA. The goal of SMI-S is to standardize storage
management using the CIM and WBEM technologies created and managed by DTMF.
SMI-S provider
For storage systems to support SMI-S, it must provide an SMI-S provider to service the SMI-S
requests. Depending on the storage system, the SMI-S provider can run on an external server or
internally on the storage system. IBM XIV and the IBM SAN Volume Controller and Storwize family
provides an SMI-S provider that runs internally on the storage system. This configuration reduces
management complexity and additional resource allocation needed for an external provider.
Windows Storage Management API (SMAPI)
With the release of Windows Server 2012, Microsoft has introduced the SMAPI. SMAPI is a Windows
Management Instrumentation (WMI)-based application programming interface (API) that provides
management for external and direct-attached storage. In addition to WMI, a set of corresponding
PowerShell cmdlets are provided.
SMAPI supports two types of plug-ins, SMI-S and SMP. The inclusion of SMI-S support allows SMAPI to
manage a wide range of storage systems including IBM XIV, IBM SAN Volume Controller, and IBM
Storwize family.
Windows PowerShell-based management and scripting of IBM storage
2
PowerShell
PowerShell is both a command-line shell and a scripting language. PowerShell is built upon the .NET
framework which provides the power of .NET while still keeping the simplicity of a shell and a scripting
language. This combination provides a very capable platform for management and automation.
Shell
As the name implies, PowerShell provides a shell interface for interactive utilization. The shell provides
similar functionality that can be found in other shells such as bash, C shell, or tcsh. The shell allows for
running the executable files, piping of output between commands, and running the scripts. An example
of the shell shown in Figure 1.
Figure 1: Example PowerShell environment window
Cmdlets
PowerShell cmdlets are lightweight commands that can be issued in the PowerShell environment. At
their core, PowerShell cmdlets are specialized .NET classes specifically designed for use in the shell.
Cmdlets can perform any arbitrary action that can be performed with the .NET framework. This allows
cmdlets to be very powerful.
A number of cmdlets are provided that allow administrators to manage their systems from the shell.
Figure 2 shows how cmdlets can be used to find the time, and how one can be used to check the
running state of a service. In addition to the built-in cmdlets, additional cmdlets can be created through
normal development with .NET, PowerShell scripting, and importing of modules or toolkits provided by
Microsoft or other vendors.
Figure 2: Finding the date and status of a service with PowerShell
Windows PowerShell-based management and scripting of IBM storage
3
.NET development
PowerShell is a built upon the .NET framework allowing it to directly use .NET objects and other .NET
languages. Development expertise in other .NET languages, such as C#, can be levered to create
new cmdlets.
PowerShell scripts
PowerShell supports scripting in the PowerShell language. Scripts can be created in any text editor
and then run within the PowerShell environment. In addition to standard scripts, PowerShell advanced
functions can be used to create cmdlets, allowing a uniformed approach to interact with PowerShell.
Modules and toolkits
Modules are a set of related PowerShell cmdlets or other functionality that can be imported into the
PowerShell environment. Commonly, PowerShell modules are distributed as PowerShell toolkits. The
toolkit installs the modules into the proper directory allowing the administrator to import the new
module as needed.
IBM storage interfaces
IBM storage systems provide multiple interfaces for management. The management options range from
command line tools such as the XCLI for XIV management to GUI-based management, as seen on the
Storwize family. IBM XIV, IBM SAN Volume Controller, and IBM Storwize family also provide the industry
standard SMI-S interface. SMAPI can use this interface to manage these devices through PowerShell.
Solution requirements
Management of IBM storage systems through PowerShell and SMAPI requires support for SMAPI in
Windows and support for SMI-S on the storage system. Following is a list of software and hardware used
during validation.
Windows Server 2012
Storwize V7000 [Link]
Solution validation
To validate the solution, this section provides three sequential validation steps. First, each individual
building block action has been validated. Second, the building blocks have been combined into a simple
Powershell script to perform some basic actions. Finally, an example of an advanced script has been
created to demonstrate the power and flexibility offered by this solution.
SMAPI and PowerShell setup and configuration
Before the SMAPI PowerShell cmdlets can be utilized, the Windows Standards-Based Storage
Management feature must first be installed on the Windows server from where the commands will be
issued. Windows Server 2012 or later is required for SMAPI support. Enablement of this feature is the
same process as enabling any Windows Server feature. Figure 3 shows the feature selection window.
Windows PowerShell-based management and scripting of IBM storage
4
Figure 3: Windows Standards-Based Storage Management feature selection window
Connecting and querying storage system information
Connecting to a storage system using SMAPI is a three-step process. For the initial connection, you need
to perform the following tasks.
Register the SMI-S provider
Select the storage system
Populate the provider cache
Query storage system information
Registering the SMI-S provider
SMI-S providers act as the communication point for managing storage systems. A single SMI-S
provider can provide management for a single storage system or multiple storage systems. The IBM
XIV, IBM SAN Volume Controller, and IBM Storwize family all provide an internal SMI-S provider. This
configuration allows for a one-to-one relationship between the provider and the storage system. Before
the provider can be accessed, it must first be registered. This process permanently registers the
SMI-S provider with the SMAPI. An example of the process follows.
The Get-StorageProvider cmdlet returns all the known storage providers. If the cmdlet is run
on a system that is yet to register a provider, Storage Spaces Management Provider is listed.
This is a provider that is registered by default and allows management of Windows storage
spaces.
Windows PowerShell-based management and scripting of IBM storage
5
PS C:\> Get-StorageProvider
Type Name Manufacturer
---- ---- ------------
SMP Storage Spaces Management Provider Microsoft Corporation
The Register-SmisProvider cmdlet can register a new SMI-S provider with SMAPI. The cmdlet
requires the SMI-S provider Uniform Resource Identifier (URI) and its credentials. This can be
supplied through the command line, a PSCredential object, or interactively. More details
regarding this cmdlet or any cmdlet can be retrieved using the Get-Help cmdlet. The following
example demonstrates registering an SMI-S provider prompting for credentials.
PS C:\> Register-SmisProvider -Uri [Link]
cmdlet Register-SmisProvider at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
Credential
PS C:\> Get-StorageProvider
Type Name Manufacturer
---- ---- ------------
SMP Storage Spaces Management Provider Microsoft Corporation
SMI-S [Link] IBM
Selecting the storage system
SMI-S providers can provide SMI-S connectivity for multiple storage systems. In the previous step, an
SMI-S provider from an IBM Storwize V7000 system was successfully registered.
The Get-StorageSubsystem cmdlet can be used to list all known storage systems. By default, the
cmdlet will query all known providers for storage systems and list them. This can be seen in the
following example.
PS C:\> Get-StorageSubsystem
FriendlyName HealthStatus OperationalStatus
------------ ------------ -----------------
Storage Spaces on WIN-M... Healthy OK
ISV7K2 Healthy OK
Alternatively, you can use the object piping abilities of PowerShell and the SMAPI cmdlets to narrow
the search. By providing the specific storage provider or providers to the Get-StorageSubsytem
cmdlet, the cmdlet selects only specific storage systems that are managed through the specified
SMI-S providers (as shown in the following example).
PS C:\> $providers = Get-StorageProvider
PS C:\> $providers
Type Name Manufacturer
---- ---- ------------
SMP Storage Spaces Management Provider Microsoft Corporation
SMI-S [Link] IBM
PS C:\> $providers[1] | Get-StorageSubsystem
FriendlyName HealthStatus OperationalStatus
------------ ------------ -----------------
ISV7K2 Healthy OK
Windows PowerShell-based management and scripting of IBM storage
6
Populating the provider cache
The SMI-S provider is now registered with SMAPI and the storage system has been discovered.
Although the storage system has been discovered, the API does not know much about the storage
systems themselves. For example, the Get-VirtualDisk cmdlet returns all known virtual disks. As
before, this cmdlet can be scoped just as the Get-StorageSubsystem cmdlet was in the previous
example. If the Get-VirtualDisk cmdlet is run at this stage, either an error or very little data would be
returned. An example of this can be seen in the following code.
PS C:\> Get-VirtualDisk
Get-VirtualDisk : The provider's cache is empty. [Request =MSFT_SMStorageVolume]
At line:1 char:1
+ Get-VirtualDisk
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_SMStorageVolume:ROOT/Microso
ft/...SFT_VirtualDisk) [Get-VirtualDisk], CimException
+ FullyQualifiedErrorId : 40003,Get-VirtualDisk
The Update-StorageProviderCache cmdlet can be used to obtain and update the provider cache. The
cmdlet performs a discovery on the specified storage system. The depth of the discovery can be
managed by the –DiscoveryLevel option. When an SMI-S provider is registered, a Level0 discovery
is performed. This explains why the Get-StorageSubsystem cmdlet successfully lists the storage
systems without first running a manual discovery. The time to complete the discovery will be
influenced by the discovery level. The possible discovery levels are:
Full – Discovers all objects on the storage provider. Full is the same as a Level3 discovery.
Level0 – Discovers the storage provider and storage subsystem objects. Level0 discovery is
performed when any storage provider is loaded by Windows.
Level1 – In addition to a Level0 discovery, a Level1 discovery also discovers storage pools,
resiliency settings, target ports, target portals, and initiator identifiers.
Level2 – In additional to a Level1 discovery, a Level2 discovery also discovers virtual disk
and masking set objects.
Level3 – Discovers all objects on the storage provider. A Level3 discovery is the same as a
Full discovery.
To perform a discovery on a specific storage system, first obtain the storage system object and then
pipe that object to the Update-StorageProviderCache cmdlet. An example of this is shown in the
following code.
PS C:\> $storageSystems = Get-StorageSubsystem
PS C:\> $storageSystems
FriendlyName HealthStatus OperationalStatus
------------ ------------ -----------------
Storage Spaces on WIN-M... Healthy OK
ISV7K2 Healthy OK
PS C:\> $storageSystems[1] | Update-StorageProviderCache -DiscoveryLevel Full
After performing the discovery, it is now possible to query other parameters of the storage system. The
following list provides some of the examples.
Listing all virtual disks
Windows PowerShell-based management and scripting of IBM storage
7
PS C:\> $storageSystems[1] | Get-VirtualDisk
FriendlyName ResiliencySe OperationalS HealthStatus IsManualAtta Size
ttingName tatus ch
------------ ------------ ------------ ------------ ------------ ----
ABG_SRM_DR OK Healthy 500 GB
JTC_TP_TS... OK Healthy 500 GB
bp_SFHA_tp1 OK Healthy 10 GB
bp_SFHA_tp2 OK Healthy 10 GB
bp_SFHA_tp3 OK Healthy 10 GB
Listing all storage pools
PS C:\> $storageSystems[1] | Get-StoragePool
FriendlyName OperationalStat HealthStatus IsPrimordial IsReadOnly
us
------------ --------------- ------------ ------------ ----------
RLB_VMWARE_S... OK Healthy False
ABG_VDI_SRM OK Healthy False
JBE_ARCHIVE_... OK Healthy False
JTC_TP_TST_P01 OK Healthy False
JTC_NTP_TST_P02 OK Healthy False
PrimordialSt... OK Healthy True
Query storage system information
A wide range of PowerShell cmdlets are provided to query the storage system. You can find detailed
information regarding the cmdlets at: [Link]/en-us/library/[Link]
The following is a more advanced example that selects all the target ports contained in a masking set.
This example uses two SMAPI PowerShell cmdlets.
Windows PowerShell-based management and scripting of IBM storage
8
Selecting target ports from a specific host
PS C:\Users\Administrator> $ss[1] | Get-MaskingSet | Where {$_.FriendlyName -like
"ISVNGP2BT7"} | Get-TargetPort
FriendlyName NodeAddress PortAddress ConnectionType
HealthStatus OperationalStatus
------------ ----------- ----------- -------------- -------
---- -----------------
00000200A120008C... 00000200A120008C... 50050768021000E1 Fibre Channel
Healthy OK
00000200A120008C... 00000200A120008C... 50050768021000E2 Fibre Channel Healthy
OK
00000200A120008C... 00000200A120008C... 50050768022000E1 Fibre Channel Healthy
OK
00000200A120008C... 00000200A120008C... 50050768022000E2 Fibre Channel Healthy
OK
Storage provisioning and management
SMAPI provides PowerShell cmdlets to perform most of the provisioning and management tasks. This
section demonstrates how storage can be allocated and provisioned to a host using only the PowerShell
cmdlets. The first example provides a detailed step-by-step walkthrough while remaining examples
assume that the reader understood the basics of the first.
Creating a new thick-provisioned volume
The following steps explain how to create a new thick-provisioned volume.
All storage systems are discovered and the required one is selected.
PS C:\> $ss = Get-StorageSubsystem
PS C:\> $ss
FriendlyName HealthStatus OperationalStatus
------------ ------------ -----------------
Storage Spaces on WIN-... Healthy OK
ISV7KD9 Healthy OK
The storage pools available on the selected storage system are listed. To determine if the
storage pool can accommodate the volume, the available size is calculated.
PS C:\> $sp = $ss[1] | Get-StoragePool
PS C:\> $sp
FriendlyName OperationalStat HealthStatus IsPrimordial IsReadOnly
us
------------ --------------- ------------ ------------ ----------
RAID5_NLSAS OK Healthy False
PrimordialSt... OK Healthy True
PS C:\> ($sp[0].size - $sp[0].availableSize)/1024/1024/1024
8374
Windows PowerShell-based management and scripting of IBM storage
9
The New-VirtualDisk cmdlet is used to allocate a new volume on the selected storage pool.
PS C:\> $sp[0] | New-VirtualDisk -FriendlyName "NewThickDisk" –ProvisioningType Fixed -
Size 1TB
FriendlyName ResiliencySe OperationalS HealthStatus IsManualAtta Size
ttingName tatus ch
------------ ------------ ------------ ------------ ------------ ----
NewThickDisk OK Healthy 1 TB
The new volume has now been created. This is automatically reflected in the Storwize or XIV GUI.
Figure 4: New thick-provisioned volume created with PowerShell
Creating a new thin-provisioned volume
Thin-provisioned volumes can be created by setting the –ProvisioningType option to thin on the
Net-VirtualDisk cmdlet.
PS C:\> $sp[0] | New-VirtualDisk -FriendlyName "NewThinDisk" -ProvisioningType Thin -
Size 1TB
FriendlyName ResiliencySe OperationalS HealthStatus IsManualAtta Size
ttingName tatus ch
------------ ------------ ------------ ------------ ------------ ----
NewThinDisk OK Healthy 1 TB
Figure 5: New thin-provisioned volume created with PowerShell
Windows PowerShell-based management and scripting of IBM storage
10
Creating a masking set (also known as hosts)
Masking sets are the core concept that determines what devices can access which volumes using
what ports. A masking set consists of initiator ports, target ports, and virtual disks. In the Storwize
nomenclature, this is equivalent to a host and its mappings. The host contains ports and those ports
are allowed to access volumes based on the mapping rules.
Defining a new masking set requires two items, first a friendly name for the masking set and then at
least one initiator port. Optionally, masking sets might have volume access specified at the creation
time. In this example, a two-step process is taken. First, the masking set is created and then the
volumes are added to the set.
Obtain the target ports for the storage system. In this example, all the target ports for the
storage system are used.
PS C:\> $tp = Get-TargetPort
PS C:\> $tp
FriendlyName NodeAddress PortAddress ConnectionTy HealthStatus OperationalS
pe tatus
------------ ----------- ----------- ------------ ------------ ------------
000002006... 000002006... 500507680... Fibre Cha... Healthy OK
000002006... 000002006... 500507680... Fibre Cha... Healthy OK
000002006... 000002006... 500507680... Fibre Cha... Warning Stopped
000002006... 000002006... 500507680... Fibre Cha... Warning Stopped
000002006... 000002006... 500507680... Fibre Cha... Healthy OK
000002006... 000002006... 500507680... Fibre Cha... Healthy OK
000002006... 000002006... 500507680... Fibre Cha... Warning Stopped
000002006... 000002006... 500507680... Fibre Cha... Warning Stopped
iqn.1986-... iqn.1986-... iqn.1986-... iSCSI Warning InService
iqn.1986-... iqn.1986-... iqn.1986-... iSCSI Warning InService
iqn.1986-... iqn.1986-... iqn.1986-... iSCSI Warning InService
iqn.1986-... iqn.1986-... iqn.1986-... iSCSI Warning InService
The New-MaskingSet cmdlet is used to create a new masking set. A warning will be issued
due to a missing host type. This is expected because the Net-MaskingSet cmdlet does not
provide a host type that correlates to the Generic host type in Storwize. Storwize defaults to a
Generic host type in this case.
PS C:\> $ss[1] | New-MaskingSet -FriendlyName "NewHost" -InitiatorAddress
('10000000C9FC8A04','10000000C9FC8A05') -TargetPortAddress $[Link]
New-MaskingSet : The HostType requested is not supported.
Extended information: Warning: StorageClientSettingData objects are not
supported on the provider
At line:1 char:10
+ $ss[1] | New-MaskingSet -FriendlyName "NewHost" –InitiatorAddress
('10000000C9FC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
+ CategoryInfo : InvalidArgument: (StorageWMI:ROOT/Microsoft/..
.torageSubSystem) [New-MaskingSet], CimException
+ FullyQualifiedErrorId : StorageWMI 52001,New-MaskingSet
Windows PowerShell-based management and scripting of IBM storage
11
Figure 6: Port definitions for a host created with PowerShell
Mapping a volume to a host
The process of mapping a volume to a host allows the host to access the specified volumes. In the
context of the PowerShell cmdlets, this is equivalent to adding a volume to a masking set.
Select the virtual disk that will be mapped.
PS C:\> $disks = $ss[1] | Get-VirtualDisk
PS C:\> $disks[0]
FriendlyName ResiliencySe OperationalS HealthStatus IsManualAtta Size
ttingName tatus ch
------------ ------------ ------------ ------------ ------------ ----
NewThickDisk OK Healthy 1 TB
Select the masking set, also known as the host.
PS C:\> $ms = $ss[1] | Get-MaskingSet
PS C:\> $ms[1]
FriendlyName HostType
------------ --------
NewHost
Add the volume to the masking set using Add-VirtualDiskToMaskingSet.
PS C:\> $ms[1] | Add-VirtualDiskToMaskingSet -VirtualDiskNames $disks[1].name
-DeviceAccess ReadWrite
Verify the mapping.
PS C:\> $ms[1] | Get-VirtualDisk
FriendlyName ResiliencySe OperationalS HealthStatus IsManualAtta Size
ttingName tatus ch
------------ ------------ ------------ ------------ ------------ ----
NewThinDisk OK Healthy 1 TB
Windows PowerShell-based management and scripting of IBM storage
12
Figure 7: Volume mapped to host using PowerShell
Creating repeatable automation with scripts
Many management tasks are repetitive in nature. Scripting of the tasks can reduce the run time and error
rate. PowerShell scripting capabilities tied with SMAPI provide a very capable platform for developing
automation with IBM storage.
PowerShell scripting overview
As with most other shells, PowerShell provides the capability to run user-made scripts. Scripts contain
lines of PowerShell commands that will be run when the script is run. In additional to simple shell
commands and cmdlets, the PowerShell language provides the features you would expect from an
object-oriented programming language. Functions and classes are supported thanks to the .NET
framework.
PowerShell scripting can be as advanced, or as simple, as the user would like. Novice users can use
the basic scripting support to implement repeatable tasks. Advanced developers can use the power of
PowerShell to develop advanced functions and modules allowing for seamless interaction with the
other PowerShell cmdlets. Countless resources might be found online that provide tutorials and
detailed information regarding PowerShell scripting.
Basic PowerShell script example
To demonstrate basic PowerShell scripting, a single script that reports the utilization of all storage
pools has been created. The script does not perform any prerequisite connectivity actions, although
that might easily be implemented.
# Select all storage pools.
$storagePools = Get-StoragePool
# Loop through every storage pool.
foreach ($storagePool in $storagePools) {
# Calcualte the total bytes free.
$bytesFree = $[Link] - $[Link]
# Convert to gigabytes free.
$gigabytesFree = $bytesFree/1024/1024/1024
# Write the result to the shell.
Write-Host $[Link] $gigabytesFree"GB"
}
Windows PowerShell-based management and scripting of IBM storage
13
PS C:\> .\basicExample.ps1
Primordial 40GB
RAID5_NLSAS 7349GB
PrimordialStoragePool 4109.0126953125GB
Advanced PowerShell users can modify this script to create an advanced function providing users with
a cmdlet to perform the same task. The following script has been created to demonstrate the usage of
a PowerShell advanced function. Many improvements can be added to the function such as allowing
input to limit which storage subsystems are searched and returning the values as an object. This is a
very basic example of an advanced function.
function Get-StoragePoolUsage {
<#
.SYNOPSIS
Collects the usage information for all storage pools.
.EXAMPLE
(Get-StoragePoolUsage)[0].Usage
#>
[CmdletBinding()]
param
(
)
begin {
}
process {
# Select all storage pools.
$storagePools = Get-StoragePool
# Loop through every storage pool.
foreach ($storagePool in $storagePools) {
# Calcualte the total bytes free.
$bytesFree = $[Link] - $[Link]
# Convert to gigabytes free.
$gigabytesFree = $bytesFree/1024/1024/1024
# Write the result to the shell.
Write-Host $[Link] $gigabytesFree"GB"
}
}
}
PS C:\> . .\basicExample.ps1
PS C:\> Get-StoragePoolUsage
Primordial 40GB
RAID5_NLSAS 7349GB
PrimordialStoragePool 4109.0126953125GB
Brining it all together, Provision-Storage cmdlet
Now that each step has been demonstrated individually, a single cmdlet that implements all the
actions can be created. A detailed description of the script follows, along with the script in its entirety.
The script, as implemented, is designed to create and map a new volume from a specified storage
system to a new Windows host. The host is generated by querying the Windows operating system to
retrieve all fabric ports. All other information is provided to the script at the time of execution.
Windows PowerShell-based management and scripting of IBM storage
14
Provision-Storage usage
The Provision-Storage cmdlet must first be loaded into the environment. After loading it, you can
run it. To load the cmdlet, issue. .\Provision-Storage.ps1. The cmdlet can now be run from the
PowerShell environment. A summary of the input parameters is given in the following list.
ComputerName - The FQDN of the Windows server that the new volume should be mapped
to.
Size – The size of the new volume. For example, 100 GB, 1 TB.
StorageSubsystem – The friendly name of the storage system.
VolumeName – The name for the newly created volume.
MaskName – The name of the masking set. In Storwize terminology, this is the name of the
host.
Username – The username to use when connecting to the Windows server.
With the cmdlet loaded, and the proper SMI-S providers registered, the cmdlet can now be run.
The following example creates a new 10 GB volume named testVol and maps it to a new host,
named newHost.
PS C:\> Provision-Storage -ComputerName [Link] -StorageSubsystem ISV7KD9 -Size
10GB -VolumeName testVol -MaskName newHost
Provision-Storage script detailed explanation
This section provides a detail walk-through of the Provision-Storage script.
function Provision-Storage {
Definition of help information
This section defines the information that will be provided if Get-Help is used to inquire about
the cmdlet.
<#
.SYNOPSIS
Creates a new storage volume and maps it to the specified host.
.DESCRIPTION
Creates a new storage volume of the size specified on the storage pool
with the most space available. It then queries the provided server
to determine WWPNs. Finally it maps all discovered WWPNs to the new
volume.
.EXAMPLE
Provision-Storage -Size 10GB -ComputerName [Link] -StorageSystem ISV7k2 -Thin
.PARAMETER Size
The size of the new volume to be created.
.PARAMETER ComputerName
The FQDN or IP of the system to provision storage to.
.PARAMETER StorageSubsystem
The friendly name of the storage system.
.PARAMETER Thin
Specifies if the volume should be thin provisioned.
#>
Windows PowerShell-based management and scripting of IBM storage
15
Start cmdlet binding to build a cmdlet
This line adds the CmdletBinding attribute, allowing the script to function as cmdlet.
[CmdletBinding()]
Parameter definitions
This section defines the input parameters for the cmdlet. The attributes within the square
brackets provide parameter checking. For example, the $ComputerName input parameter has
Mandatory set to $True as well as ValidateLength set. These require the
$ComputerName parameter to be provided and the length to be within the range of 1 to 1000
characters. The ValueFromPipelineByPropertyName option is also set to $True. This
allows the parameter to be provided through the pipeline. Finally, the [String] attribute
specifies that the input parameter should be a string.
param
(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='The FQDN of the computer to provision storage to?')]
[ValidateLength(1,1000)]
[string]$ComputerName,
[Parameter(Mandatory=$True, ValueFromPipeline=$False,
HelpMessage='The size of the volume?')]
[ValidateLength(3,1000)]
[string]$Size,
[Parameter(Mandatory=$True,
HelpMessage='Friendly name of storage system?')]
[ValidateLength(1,1000)]
[string]$StorageSubsystem,
[Parameter(Mandatory=$True,
HelpMessage='Volume Name?')]
[ValidateLength(3,100)]
[string]$VolumeName,
[Parameter(Mandatory=$True)]
[string]$MaskName,
[string]$Username,
)
Begin block
The begin block allows actions to be performed before the cmdlet’s process blo1kc begins. It
is common to see one-time actions, such as clearing logs, taking place here. In this example
the begin block is empty as there is no work to be done.
begin {
}
Windows PowerShell-based management and scripting of IBM storage
16
Process block
The process block is run for each item in the pipeline. In the case of this cmdlet, only a single
item is allowed as input. If multiple items were allowed, a new method to generate masking set
names and virtual disk names would be needed.
process {
Volume size conversion
For simplicity reasons, the script performs all sizing operations with bytes. To provide a better
user experience, the script allows the user to define the size in KB, MB, GB, or TB. To allow
this, the input is processed and then converted to bytes.
# Select the size into bytes.
$sizeValues = $Size | Select-String -Pattern "^(?<num>\d+)(?<units>(G|M|T|K)B)"
| Select -expand Matches
if ($sizeValues -eq $null) {
throw "Invalid size."
}
[int64]$convertedSize = $[Link]['num'].value
switch ($[Link]['units'].value) {
"KB" {
$convertedSize = $convertedSize * 1024
}
"MB" {
$convertedSize = $convertedSize * 1024 * 1024
}
"GB" {
$convertedSize = $convertedSize * 1024 * 1024 * 1024
}
"TB" {
$convertedSize = $convertedSize * 1024 * 1024 * 1024 * 1024
}
}
Windows PowerShell-based management and scripting of IBM storage
17
Host HBA port collection
The script allows the user to specify a host by the fully qualified domain name or IP and then
collects the worldwide port name (WWPN) information remotely. To accomplish this, the script
uses Windows Management Instrumentation (WMI). By default, WMI attempts to authenticate
on the remote machine with the network credentials of the user running the script. In situations
when no domain is present, it might be necessary to specify a user. The $Username
parameter is provided to accomplish this. If the $Username parameter has a value, the
connection method prompts for a user name and password.
# Collect HBA ports.
if ($Username) {
$portsRaw = Get-WMIObject -class MSFC_FibrePortNPIVAttributes
-namespace "root\wmi"
-ComputerName $ComputerName
-Credential ($ComputerName + "\" + $Username)
}
else {
$portsRaw = Get-WMIObject -class MSFC_FibrePortNPIVAttributes
-namespace "root\wmi" -ComputerName $ComputerName
}
$portsProcessed = @()
foreach ($port in $portsRaw) {
$portsProcessed += (($[Link] | ForEach-Object { ("{0:x}" -f
$_).PadLeft(2,"0") }) -join "").toUpper().trim()
}
Select the storage system
The SMAPI is used to select the storage system specified in the $StorageSubsystem input
parameter. Then the provider cache for the storage system is updated.
# Select the storage system and get it's cache.
$ss = Get-StorageSubsystem -FriendlyName $StorageSubsystem
$ss | Update-StorageProviderCache -DiscoveryLevel Level2
Windows PowerShell-based management and scripting of IBM storage
18
Selecting a storage pool
The script must dynamically select a storage pool from the specified storage system. To do
so, the script assumes that all storage pools are acceptable for use and selects the one that is
large enough to contain the volume and has the maximum free space.
# Select a storage pool.
$candidatePools = Get-StoragePool | Where {$_.IsPrimordial -eq $false -and
($_.size - $_.allocatedSize) -gt $convertedSize}
if($candidatePools -eq $null) {
throw "No storage pool large enough"
}
$chosenPool = $null
foreach ($pool in $candidatePools) {
if ($chosenPool -eq $null) {
$chosenPool = $pool
}
elseif (($[Link] - $[Link]) -gt ($[Link] -
$[Link])) {
$chosenPool = $pool
}
}
Creating a volume
A new volume is created using the New-VirtualDisk cmdlet.
# Create the new volume.
$result = $chosenPool | New-VirtualDisk -FriendlyName $VolumeName -
ProvisioningType Fixed -Size $convertedSize
Creating a masking set
First, the target ports of the storage system are selected. Next, a new masking set is created
with the New-MaskingSet cmdlet.
# Build new mask and map new volume.
$targetPorts = Get-TargetPort -StorageSubsystem $ss
$ms = New-MaskingSet -StorageSubsystemFriendlyName $[Link] -
InitiatorAddress $portsProcessed -TargetPortAddress $[Link] -
FriendlyName $MaskName
Adding the volume to the masking set
The masking set that was just created is selected. The newly created virtual disk is added to
the masking set using the Add-VirtualDiskToMaskingSet cmdlet.
$ms = Get-MaskingSet -FriendlyName $MaskName
$vs = Get-VirtualDisk -FriendlyName $VolumeName
$ms | Add-VirtualDiskToMaskingSet -VirtualDiskNames $[Link] -DeviceAccess
ReadWrite
}
}
Windows PowerShell-based management and scripting of IBM storage
19
Provisioning-Storage complete script
function Provision-Storage {
<#
.SYNOPSIS
Creates a new storage volume and maps it to the specified host.
.DESCRIPTION
Creates a new storage volume of the size specified on the storage pool
with the most space available. It then queries the provided server
to determine WWPNs. Finally it maps all discovered WWPNs to the new
volume.
.EXAMPLE
Provision-Storage -Size 10GB -ComputerName [Link] -StorageSystem ISV7k2 -Thin
.PARAMETER Size
The size of the new volume to be created.
.PARAMETER ComputerName
The FQDN or IP of the system to provision storage to.
.PARAMETER StorageSubsystem
The friendly name of the storage system.
.PARAMETER Thin
Specifies if the volume should be thin provisioned.
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='The FQDN of the computer to provision storage to?')]
[ValidateLength(1,1000)]
[string]$ComputerName,
[Parameter(Mandatory=$True, ValueFromPipeline=$False,
HelpMessage='The size of the volume?')]
[ValidateLength(3,1000)]
[string]$Size,
[Parameter(Mandatory=$True,
HelpMessage='Friendly name of storage system?')]
[ValidateLength(1,1000)]
[string]$StorageSubsystem,
[Parameter(Mandatory=$True,
HelpMessage='Volume Name?')]
[ValidateLength(3,100)]
[string]$VolumeName,
[Parameter(Mandatory=$True)]
[string]$MaskName,
[string]$Username,
[bool]$Thin
)
begin {
}
process {
# Select the size into bytes.
$sizeValues = $Size | Select-String -Pattern "^(?<num>\d+)(?<units>(G|M|T|K)B)"
| Select -expand Matches
if ($sizeValues -eq $null) {
throw "Invalid size."
}
Windows PowerShell-based management and scripting of IBM storage
20
[int64]$convertedSize = $[Link]['num'].value
switch ($[Link]['units'].value) {
"KB" {
$convertedSize = $convertedSize * 1024
}
"MB" {
$convertedSize = $convertedSize * 1024 * 1024
}
"GB" {
$convertedSize = $convertedSize * 1024 * 1024 * 1024
}
"TB" {
$convertedSize = $convertedSize * 1024 * 1024 * 1024 * 1024
}
}
# Collect HBA ports.
if ($Username) {
$portsRaw = Get-WMIObject -class MSFC_FibrePortNPIVAttributes -namespace
"root\wmi" -ComputerName $ComputerName -Credential ($ComputerName + "\" + $Username)
}
else {
$portsRaw = Get-WMIObject -class MSFC_FibrePortNPIVAttributes -namespace
"root\wmi" -ComputerName $ComputerName
}
$portsProcessed = @()
foreach ($port in $portsRaw) {
$portsProcessed += (($[Link] | ForEach-Object { ("{0:x}" -f
$_).PadLeft(2,"0") }) -join "").toUpper().trim()
}
# Select the storage system and get it's cache.
$ss = Get-StorageSubsystem -FriendlyName $StorageSubsystem
$ss | Update-StorageProviderCache -DiscoveryLevel Level2
# Select a storage pool.
$candidatePools = Get-StoragePool | Where {$_.IsPrimordial -eq $false -and
($_.size - $_.allocatedSize) -gt $convertedSize}
if($candidatePools -eq $null) {
throw "No storage pool large enough"
}
$chosenPool = $null
foreach ($pool in $candidatePools) {
if ($chosenPool -eq $null) {
$chosenPool = $pool
}
elseif (($[Link] - $[Link]) -gt ($[Link] -
$[Link])) {
$chosenPool = $pool
}
}
# Create the new volume.
$result = $chosenPool | New-VirtualDisk -FriendlyName $VolumeName -
ProvisioningType Fixed -Size $convertedSize
# Build new mask and map new volume.
$targetPorts = Get-TargetPort -StorageSubsystem $ss
$ms = New-MaskingSet -StorageSubsystemFriendlyName $[Link] -
InitiatorAddress $portsProcessed -TargetPortAddress $[Link] -
FriendlyName $MaskName
$ms = Get-MaskingSet -FriendlyName $MaskName
$vs = Get-VirtualDisk -FriendlyName $VolumeName
$ms | Add-VirtualDiskToMaskingSet -VirtualDiskNames $[Link] -DeviceAccess
ReadWrite
}
}
Windows PowerShell-based management and scripting of IBM storage
21
Summary
The migration of IT infrastructure to the cloud model has prompted IT administrators to look for new tools,
methods, and processes for IT management. The combined support from IBM and Microsoft for
standards-based management, such as SMI-S, provides the framework to tackle this new model. The
SMAPI along with PowerShell provide a very capable tool that allows administrators to reliably and
efficiently manage IBM XIV, SAN Volume Controller, and Storwize family disk systems.
Windows PowerShell-based management and scripting of IBM storage
22
Resources
The following websites provide useful references to supplement the information contained in this paper:
IBM Systems on PartnerWorld
[Link]/partnerworld/systems
IBM Redbooks
[Link]/redbooks
IBM Storwize V7000
[Link]/storage/storwizev7000
IBM Techdocs Library
[Link]/support/techdocs/[Link]/Web/TechDocs
VMware vSphere 5 Documentation Center
[Link]/vsphere-
50/[Link]?topic=/[Link].doc_50/GUID-7C9A1E23-7FCD-4295-
[Link]
Distributed Management Task Force, Inc. Standards
[Link]/standards
Storage Networking Industry Association
[Link]
An Introduction to Storage Management in Windows Server 2012
[Link]/b/san/archive/2012/06/26/an-introduction-to-storage-management-in-
[Link]
Windows PowerShell-based management and scripting of IBM storage
23
Trademarks and special notices
© Copyright IBM Corporation 2013.
References in this document to IBM products or services do not imply that IBM intends to make them
available in every country.
IBM, the IBM logo, and [Link] are trademarks or registered trademarks of International Business
Machines Corporation in the United States, other countries, or both. If these and other IBM trademarked
terms are marked on their first occurrence in this information with a trademark symbol (® or ™), these
symbols indicate U.S. registered or common law trademarks owned by IBM at the time this information
was published. Such trademarks may also be registered or common law trademarks in other countries. A
current list of IBM trademarks is available on the Web at "Copyright and trademark information" at
[Link]/legal/[Link].
Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the
United States, other countries, or both.
Other company, product, or service names may be trademarks or service marks of others.
Information is provided "AS IS" without warranty of any kind.
All customer examples described are presented as illustrations of how those customers have used IBM
products and the results they may have achieved. Actual environmental costs and performance
characteristics may vary by customer.
Information concerning non-IBM products was obtained from a supplier of these products, published
announcement material, or other publicly available sources and does not constitute an endorsement of
such products by IBM. Sources for non-IBM list prices and performance numbers are taken from publicly
available information, including vendor announcements and vendor worldwide homepages. IBM has not
tested these products and cannot confirm the accuracy of performance, capability, or any other claims
related to non-IBM products. Questions on the capability of non-IBM products should be addressed to the
supplier of those products.
All statements regarding IBM future direction and intent are subject to change or withdrawal without notice,
and represent goals and objectives only. Contact your local IBM office or IBM authorized reseller for the
full text of the specific Statement of Direction.
Some information addresses anticipated future capabilities. Such information is not intended as a definitive
statement of a commitment to specific levels of performance, function or delivery schedules with respect to
any future products. Such commitments are only made in IBM product announcements. The information is
presented here to communicate IBM's current investment and development activities as a good faith effort
to help with our customers' future planning.
Performance is based on measurements and projections using standard IBM benchmarks in a controlled
environment. The actual throughput or performance that any user will experience will vary depending upon
considerations such as the amount of multiprogramming in the user's job stream, the I/O configuration, the
storage configuration, and the workload processed. Therefore, no assurance can be given that an
individual user will achieve throughput or performance improvements equivalent to the ratios stated here.
Photographs shown are of engineering prototypes. Changes may be incorporated in production models.
Windows PowerShell-based management and scripting of IBM storage
24
Any references in this information to non-IBM websites are provided for convenience only and do not in
any manner serve as an endorsement of those websites. The materials at those websites are not part of
the materials for this IBM product and use of those websites is at your own risk.
Windows PowerShell-based management and scripting of IBM storage
25