Friday, August 27, 2010

Fun with Powershell OnTap

What is PowerShell?
PowerShell is a command-line shell and scripting language provided by Microsoft which adds capabilities to its predecessor, cmd.exe. Commands that previously worked in cmd.exe will work with PowerShell. In addition PowerShell 2 provides 129 cmdlets sharing a similar verb-noun syntax. For example, the command to list the contents of a directory is Get-ChildItem:

PS C:\scripts> get-childitem

Directory: C:\scripts

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 8/18/2010 10:50 AM 6446 fun_with_netapp.ps1
-a--- 8/17/2010 5:40 PM 87 netapp.ps1
-a--- 8/17/2010 6:14 PM 1376 netapp_credentials.enc.xml
-a--- 8/17/2010 9:37 PM 1376 share_credentials.enc.xml

Built-in aliases are available for this command, and others. In this case both "dir" and "ls" will work in the PowerShell.

PowerShell is an object-oriented scripting language with a C# type syntax. It has access to the .NET framework extending its capabilities. Preferences can be stored in profiles familiar to administrators running shell scripts on other platforms.

Extensive help is available using the Get-Help cmdlet on any cmdlet available, as well as tab completion allowing the scripter to toggle through available commands.

PowerShell ONTAP
PowerShell OnTap is a module that adds over 100 cmdlets exposing the API of NetApp filers. After importing the module several more cmdlets are available for managing a NetApp filer. After logging into a filer, the cmdlets may be used to create and remove aggregates, volumes, shares and much more. NetApp community support is strong, and PowerShell OnTap is now known as the Data OnTap PowerShell Toolkit.

Here are some examples using PowerShell and the Data OnTap Toolkit:

Adding the snap in makes the DataOnTap cmdlets available to Powershell
Import-Module DataOnTap

Logging into the NetApp
PS C:\scripts> Connect-NaController -Credential $Credential

OntapiMajorVersion : 1
OntapiMinorVersion : 12
Protocol : HTTPS
Vfiler :
Name :
Address :
Port : 443
Credentials : System.Net.NetworkCredential
ValidateIncoming : False
ValidateOutgoing : False
Trace : False

Creating a flexvol
PS C:\scripts> New-NaVol myvol aggr0 100g

ChecksumStyle : block
CloneChildren :
CloneParent :
ContainingAggregate : aggr0
DiskCount : 6
FilesTotal : 3112959
FilesUsed : 100
IsChecksumEnabled : True
IsInconsistent : False
IsSnaplock : False
IsUnrecoverable : False
MirrorStatus : unmirrored
Name : myvol
PercentageUsed : 0
PlexCount : 1
Plexes : {/aggr0/plex0}
QuotaInit : 0
RaidSize : 16
RaidStatus : raid_dp
Reserve : 0
ReserveRequired : 0
ReserveUsed : 0
Sis :
SizeAvailable : 85899231232
SizeTotal : 85899345920
SizeUsed : 114688
SnaplockType :
SpaceReserve : volume
SpaceReserveEnabled : True
State : online
Type : flex
Uuid : 3e242ae8-ac8e-11df-ac68-00a09802a2c0
IsUnrecoverableSpecified : True
PercentageUsedSpecified : True
SpaceReserveEnabledSpecified : True

Creating a CIFS share for the new volume
PS C:\scripts> Add-NaCifsShare myvol /vol/myvol

Caching :
Description :
DirUmask :
FileUmask :
Forcegroup :
IsSymlinkStrictSecurity :
IsVolOffline :
IsVscan :
IsVscanread :
IsWidelink :
Maxusers :
MountPoint : /vol/myvol
ShareName : myvol
Umask :
DirUmaskSpecified : False
FileUmaskSpecified : False
IsSymlinkStrictSecuritySpecified : False
IsVolOfflineSpecified : False
IsVscanSpecified : False
IsVscanreadSpecified : False
IsWidelinkSpecified : False
MaxusersSpecified : False
UmaskSpecified : False

After creating a CIFs volume, we can continue to automate the procedure by mapping the volume to our host in PowerShell
PS C:\scripts> $net = $(New-Object -ComObject WScript.Network)
PS C:\scripts> $net.MapNetworkDrive("Z:", "\\\myvol", "false", $Username, $Password )

PowerShell supports functions allowing the administrator to write and schedule scripts automating many of the Windows and NetApp tasks.

Useful Links

Downloading PowerShell 2.0

To run PowerShell, you will need the .NET framework

Finally, to download the Data OnTap PowerShell Toolkit
You will need a working NetApp Now account to access this link

The Data OnTap PowerShell Toolkit communtiy provides downloads, sample scripts and communtiy support

No comments:

Post a Comment