Microsoft Virtualization Discussions

Changing rsh to PowerShell for Win2012

Jalal_
3,824 Views

Hi,

 

Can someone please give me tips to change my script from rsh (win2003) to PowerShell!!!?

 

 

Function 1:

 

'############################################################################################
'  GetNetAppQuota()
'  Ermittelt die insgesamt vergebene Quota (in MB) auf einem NetApp-Server Volume
'############################################################################################
Private Function GetNetAppQuota(lstrServer, lstrVolume)

    On Error Resume Next
    GetNetAppQuota = 0

    Dim lWshShell, loExec
    Dim lstrLine, lsz1
    Dim lnQuota
    
    If bDebug Then Call Logging("GetNetAppQuota().Param: " & lstrServer &", "& lstrVolume)

    set lWshShell = CreateObject("WScript.Shell")

    lsz1 = ""
    Set loExec = lWshShell.Exec (Join(Array("rsh", lstrServer, "-n", "quota report")))
    Do While Not loExec.StdOut.AtEndOfStream
        lstrLine = MyTrimSpaces(replace(loExec.StdOut.ReadLine, vbCr, ""))
        'wscript.echo lstrLine    
        lsz1 = split(lstrLine, " ")
        if lsz1(0) <> "K-Bytes" And lsz1(0) <> "Type" And lsz1(0) <> "-----"  And lsz1(1) <> "*" then
            if lsz1(2) = lstrVolume then lnQuota = lnQuota + lsz1(5) / 1024
        end if
    Loop

    GetNetAppQuota = lnQuota

    If bDebug Then Call Logging("GetNetAppQuota().Return: " & GetNetAppQuota)

End Function

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

 

 

 

Function 2:

 

'############################################################################################
Private Function ExecRsh (host, cmd)
    On Error Resume Next
    Dim WshShell
    
    If bDebug Then Call Logging("ExecRsh().Param: " & host & ", " & cmd)
        
    Set WshShell = CreateObject("WScript.Shell")
    if bDebug then Call Logging("ExecRsh().exec: " & Join(Array("rsh", host, "-n", cmd)))
    Set ExecRsh = WshShell.Exec (Join(Array("rsh", host, "-n", cmd)))
    Set WshShell = Nothing

    If bDebug Then Call Logging("ExecRsh().Return: " & ExecRsh)

End Function

 

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

 

 

 

 

Thanks

Jalal_

4 REPLIES 4

JGPSHNTAP
3,811 Views

Well, this isn't that hard, but you have to start be reading the getting started with powershell documentation.

 

RSH should be eliminated at all cause b/c of the massive security hole, so you are going down the correct route..

 

I'm not going to write it before you, but you can get started by reading the help for the powershell toolkit

 

Connect to controllers via https or rpc with connect-nacontroller

 

Also, 

 

For any help, you can do get-nahelp *quota*

 

 

asulliva
3,784 Views

Hello @Jalal_,

 

As @JGPSHNTAP mentioned, be sure to give the docs a read.  Once you install the NetApp PowerShell Toolkit you can access the cmdlet documentation with the command "Show-NcHelp" (or Show-NaHelp for 7-mode).  This makes all the cmdlet definitions, examples, etc. available in HTML format.

 

The first script you have is simply doing a "quota report" against your storage system.  There are two ways you can do this: 1) use "Invoke-NcSsh" (or Invoke-NaSsh if using 7-mode) to execute the same "quota report" command against the system and parse the result in PowerShell vs VBscript, or 2) use the quota cmdlets...Get-NcQuotaReport (or Get-NaQuotaReport if 7-mode) to get the information.  I believe that the entire first function can be replaced by this...but it's hard to tell without knowing 7-mode vs clustered or what the expected output is.

 

 

(Measure-Object -Sum (Get-NcQuotaReport).DiskUsed).Sum / 1024

The second function will simply execute any command against the controller using rsh.  This can be replaced using the above mentioned "Invoke-NcSsh" (or Inovke-NaSsh for 7-mode).

 

Hope that helps.

 

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Jalal_
3,769 Views

Is there an example for my functions

asulliva
3,715 Views

Not sure what type of example you're looking for.  Your "ExecRsh" can be replaced by the "Invoke-NcSsh" (or "Invoke-NaSsh" for 7-mode), but it's not a 1-for-1...you will need to do some updates to the script which is calling the fuction, the first being convert it from VBscript to PowerShell.

 

The other function I gave an example of in the other response...it all depends on what output you're looking for.

 

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
Public