Microsoft Virtualization Discussions

Netapp Powershell Manager

KARL_BUSTAMANTE
6,310 Views

Hi all,

I just posted a useful script, we could ameliorate for the community.

http://mymsworld.kahsky.com/?p=54

Regards,

Karl

<# 

.SYNOPSIS 

       Configures and show dirrerent data from netapp servers

.DESCRIPTION 

    Manage netapp server from powershell

.NOTES 

    Versions                : 1.0 - See changelog at http://mymsworld.kahsky.com/?p=54

    Wish list                : -

    Rights Required            : Local administrator on server;dns administrator for dns population

    Netapp Version            : 8.1

    Author                   : Karl Bustamante

    Email/Blog                : karl.bustamante@gmail.com     http://mymsworld.kahsky.com

    Dedicated Post            : http://mymsworld.kahsky.com/?p=54

    Disclaimer               : You running this script means you won't blame me if this breaks your stuff.

    Ressources                 :

.LINK 

        http://mymsworld.kahsky.com

.EXAMPLE

    .\netappvservermanager.ps1

.INPUTS

    None. You cannot pipe objects to this script.

#>

#Requires -Version 2.0

$ErrorActionPreference="SilentlyContinue"

Stop-Transcript | out-null

#$ErrorActionPreference = "Continue"

$ErrorActionPreference="SilentlyContinue"

#Requires -Version 2.0

[string] $FilenameTranscript = $MyInvocation.MyCommand.Name + " " + (hostname)+ " {0:yyyy-MM-dd hh-mmtt}.log" -f (Get-Date)

Start-Transcript -path .\$FilenameTranscript | Out-Null

$error.clear()

[string]$global:vservername = ""

function criticalError{

Write-Host "Error" -ForegroundColor black -backgroundcolor red

Stop-Transcript

Write-Host "Press any key to continue ..." -ForegroundColor yellow

$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

exit

}

clear

Write-Host "##########################################################################"

Write-Host "#     NetApp Powershell                                                  #"

Write-Host "#                                                                        #"

Write-Host "##########################################################################"

Write-Host "#   Author      : Karl Bustamante                                        #"

Write-Host "#   Date        : 12.06.2013                                             #"

Write-Host "#   Version     : 1.0                                                    #"

Write-Host "#   Comment     : This program is set to use powershell for netapp       #"

Write-Host "#   Modified by :                                                        #"

Write-Host "#   Date        :                                                        #"

Write-Host "#   Comment     :                                                        #"

Write-Host "#                                                                        #"

Write-Host "##########################################################################"

Write-Host " "

# Detect correct OS here and exit if no match (we intentionally truncate the last character to account for service packs)

Write-Host "System Version (OS) : " -NoNewLine

Write-Host (Get-WMIObject win32_OperatingSystem).Version -NoNewLine

if ((Get-WMIObject win32_OperatingSystem).Version -notmatch '6.1.760'){

    Write-Host "..............................[    " -NoNewline

    Write-Host "ERROR"-ForeGroundColor red -NoNewline

    Write-Host "    ]"

    Write-Host "`nThis script requires a version of Windows 7 or Windows Server 2008 R2, " -ForegroundColor Red

    Write-Host "which this is not. Exiting...`n" -ForegroundColor Red

    criticalError

} #end OS detection

Write-Host "..............................[     " -NoNewline

Write-Host "OK!" -ForeGroundColor Green -NoNewline

Write-Host "    ]"

function dltoolkit {

    cd "C:\Program Files\Internet Explorer\"

    ./iexplore.exe 'https://communities.netapp.com/servlet/JiveServlet/downloadBody/22259-102-2-46799/DataONTAP.msi.zip'

    cd /

}

# Function to test if netapp module is available

Function Get-MyModule {

    Param([string]$name)

    if(-not(Get-Module -name $name))

    { if(Get-Module -ListAvailable | Where-Object { $_.name -eq $name })

    { Import-Module -Name $name

    Write-Host "`nThe"  -NoNewLine

    Write-Host " <$name> "  -ForegroundColor yellow -NoNewLine

    Write-Host "module has been loaded!"

    }

    else {

        Write-Host -BackgroundColor Red "`n<$name>" -NoNewLine

        Write-Host " module has not been loaded " -BackgroundColor Red -ForegroundColor yellow

        $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes",""

        $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No",""

        $choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no)

        $caption = "Powershell Toolkit Download"

        $message = "Do you want to download the powershell toolkit for NetApp?"

        $result = $Host.UI.PromptForChoice($caption,$message,$choices,0)

        if($result -eq 0) { dltoolkit }

        if($result -eq 1) { criticalError }

        criticalError

    }

    } # end if not module

    else {

        Write-Host "`nThe" -NoNewLine

        Write-Host " <$name> "  -ForegroundColor yellow -NoNewLine

        Write-Host "module is already loaded!" }

    }

Get-Mymodule -name "dataontap"

$cluster = New-Object System.Management.Automation.Host.ChoiceDescription "&Cluster",""

$7node = New-Object System.Management.Automation.Host.ChoiceDescription "&7-mode",""

$choices = [System.Management.Automation.Host.ChoiceDescription[]]($cluster,$7node)

$caption = "Select your server mode"

$message = "Do you want to connect to a cluster-mode or 7-mode server?"

$result = $Host.UI.PromptForChoice($caption,$message,$choices,0)

if($result -eq 0) { $servermode = "cluster"}

if($result -eq 1) { $servermode = "7-node" }

if ($servermode -like "cluster")

{

function vserverconnect {

#connection to Vserver :

    write-host "-------------------------------------------------------------------" -foregroundcolor blue

    write-host ""

    write-host "Connect to a Vserver NetApp" -foregroundcolor green

    write-host "---------------------------" -foregroundcolor green

    write-host ""

    write-host ""

    $global:vservername = read-host "Enter the vserver name or IP Address"

    $pass = read-host "Enter admin password (Written as plain text) "

    $password = ConvertTo-SecureString $pass -AsPlainText -Force

    $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "admin",$password

    Connect-NcController $global:vservername -Credential $cred | FL *

   

    #write-host $global:vservername

    start-sleep 2

    #write-host "Press any key to continue" -foregroundcolor yellow

    #$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

   

    $connected  = "true"   

    #Add-NcHostIscsiTargetPortal

}

vserverconnect

function populatedns{

    write-host "-------------------------------------------------------------------" -foregroundcolor blue

    write-host ""

    write-host "DNS automatic input" -foregroundcolor green

    write-host "---------------------------" -foregroundcolor green

    write-host ""

    write-host ""

    $AddrEntry = ""

    while ($AddrEntry -eq ""){

        $AddrEntry = read-host "Enter the start of IP Addresses you want to use(ex: 192.168.81) "

    }

    write-host ""

    write-host "DNS Servers :"

    Get-NcNetDns | where { $_.NameServers -like "*"+$AddrEntry+"*" } | foreach {

        $dnsserver = $_.nameservers

        $dnsdomain = $_.Domains

        write-host $dnsserver -NoNewline -foregroundcolor yellow

        write-host "  |  " -NoNewline -foregroundcolor yellow

        write-host $dnsdomain -foregroundcolor yellow

    }

        write-host "-------------------------------------------------------------------"

        Get-NcNetInterface | where { $_.address -like "*"+$AddrEntry+"*"} | select interfacename,vserver,address | foreach {       

            Write-Host $_.address -NoNewline

            Write-Host "   " -NoNewline

            Write-Host $_.vserver

        }

        write-host "-------------------------------------------------------------------"

        Get-NcNetInterface | where { $_.address -like "*"+$AddrEntry+"*"} | select interfacename,vserver,address | foreach {

           

            [string]$vserv = $_.vserver

            [string]$ipaddr = $_.address

       

            Write-Host "Inserting new HOST(A): "

            Write-Host "$vserv ($ipaddr)"

            Write-Host "into DNS............................................[" -NoNewLine

       

            Write-Host "   Creating   " -ForegroundColor yellow -NoNewLine

            Write-Host "]" -NoNewLine

       

            # FIND DNS FROM NETAPP CONFIG!!!!!

           

            $x = "dnscmd " + $dnsserver + " /RecordAdd " + $dnsdomain + " $vserv A $ipaddr"

           

            invoke-expression $x | out-null

            start-sleep 1

            Write-Host "`b`b`b`b`b`b`b`b`b`b`b`b`b`b     OK!" -ForegroundColor green -NoNewLine

            Write-Host "     ]"

            #write-host "DEBUG :" -foregroundcolor yellow -backgroundcolor red

            #write-host $x -foregroundcolor yellow -backgroundcolor red

    }

    write-host "Press any key to continue" -foregroundcolor yellow

    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

}

[string] $Menu = @'

    ==============================================================

    NetApp - script - Connected to

'@

$Menu += $global:vservername

$Menu += @'

    ==============================================================

    Menu

    ##############################################################

   

    1) Download Powershell Toolkit

    2) Populate DNS values

    3) View Volume

    4) View Aggregate

    5)

    6) View Network config

    7) Reconnect to server

    8) Exit programm

   

Please select an option  

'@

function viewclustervolumes {

    get-ncvol

    write-host "Press any key to continue" -foregroundcolor yellow

    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

}

function viewclusteraggregate {

    get-ncaggr | select Name,nccontroller,nodes,state,totalsize,used,disks,raidtype

    write-host "Press any key to continue" -foregroundcolor yellow

    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

}

function networkshow {

    Get-NcNetInterface

    Get-NcNetDns

    Get-NcNetPort

    Get-NcNetRoutingGroupRoute

    write-host "Press any key to continue" -foregroundcolor yellow

    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

}

do{

    cls

    if ($MenuOption -ne "None") {Write-Host "`nConnected server : "$global:vservername" | Last command: "$MenuOption -BackgroundColor Yellow -ForegroundColor black}

        $MenuOption = Read-Host $Menu

    switch ($MenuOption) {

        1    { # populate dns values

             dltoolkit

        }

        2    { # populate dns values

             populatedns

        }

        3    { # view volumes

             viewclustervolumes

        }

        4    { # view aggregates

             viewclusteraggregate

        }

        6    {

            networkshow

        }

        7    {

            vserverconnect

        }

        8 {    #exit

            cls

            $connected = "false"

            write-host "-----------------------------------------------------------------------" -foregroundcolor yellow

            stop-transcript

            write-host "-----------------------------------------------------------------------" -foregroundcolor yellow

           

            exit

        }

        Default {

            Write-Host "You haven't selected any of the available options."

        }

    }

} while ($MenuOption -ne 8)

}

else{

    write-host "7-mode is not yet supported for this script" -foregroundcolor red -backgroundcolor yellow

    criticalerror

}

7 REPLIES 7

JSHACHER11
6,310 Views

wow!

Karl, how do I make my scripts run in the blue screen? Every time I run a script it opens up in the small black screen and not in the big blue screen, why is that?

KARL_BUSTAMANTE
6,310 Views

Hi Joel,

This is normal. Powershell runs black screen when you right-click and select "Run with powershell".

If you wish to run with the blue screen, just launch a powershell console , and then, navigate to the folder where the script is located( with cd command), run the script like this :

PS C:\> ./yourscript.ps1

JSHACHER11
6,310 Views

Karl,

I'm aware of how to open the blue console. The problem is that when I run a script (double-click), it opens up in the black screen. I want it to run in the blue screen. Is that possible?

vinith
6,310 Views

Which version of powershell are you using?

KARL_BUSTAMANTE
6,310 Views

That's the first version of the script I'm creating.

I'm using version 1 and version 2 which are working perfectly on any powershell version.

Why?

KARL_BUSTAMANTE
6,310 Views

Joel,

A normal powershell console is black. The blue console is only defined by the shorcut parameters on windows. If you want that every powershell console looks blue, launch this script on a powershell console:

Set-StrictMode -Version Latest

Push-Location
Set-Location HKCU:\Console
New-Item '.\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe'
Set-Location '.\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe'

New-ItemProperty . ColorTable00 -type DWORD -value 0x00562401
New-ItemProperty . ColorTable07 -type DWORD -value 0x00f0edee
New-ItemProperty . FaceName -type STRING -value "Terminal"
New-ItemProperty . FontFamily -type DWORD -value 0x00000036
New-ItemProperty . FontSize -type DWORD -value 0x000c0000
New-ItemProperty . FontWeight -type DWORD -value 0x00000190
New-ItemProperty . HistoryNoDup -type DWORD -value 0x00000000
New-ItemProperty . QuickEdit -type DWORD -value 0x00000001
New-ItemProperty . ScreenBufferSize -type DWORD -value 0x0bb80078
New-ItemProperty . WindowSize -type DWORD -value 0x00320078
Pop-Location

JSHACHER11
6,310 Views

nice. not blue but good enough

thanks

Public