Microsoft Virtualization Discussions

Help with NetApp PowerShell Toolkit in external script called by VMware SRM

I'm having a very weird problem with VMware SRM running a script written in PowerShell during a custom step in a test/recovery plan.

 

The code in question is very simple (edited here for brevity):

$pwx = Get-Content C:\SRM_Scripts\credentials\$($Vserver).txt | ConvertTo-SecureString

$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ClusterUser,$pwx
if($Credential.UserName -ne $ClusterUser){
    mylogger -LogFile $Log -Message "    Unable to retrieve credentials for $Cluster.  Cannot continue." -Color Red
    exit 1
} else {
    mylogger -LogFile $Log -Message "    Retrieved credentials for $($Credential.UserName)" -Color Green
}

$ClusterConn = Connect-NcController -Name $Cluster -Vserver $Vserver -Credential $Credential
mylogger -LogFile $Log -Message "Returned properties: Name:$($ClusterConn.Name) Address:$($ClusterConn.Address) Vserver:$($ClusterConn.Vserver) Version:$($ClusterConn.Version)" -Color Yellow

if($ClusterConn.Name -ne $Cluster){
    mylogger -LogFile $Log -Message "Unable to connect to $Cluster, check credentials or other connection attributes.  Cannot continue." -Color Red
    exit 1
} else {
    mylogger -LogFile $Log -Message "Connection to $($ClusterConn.Name) established" -Color Green
}

When I run this script (the above code is just a snippit from the larger script) from a PowerShell command prompt launched as the local account that SRM runs as, srmadmin, my script works correctly.  When I call this script from within SRM as a custom step in a test/recovery plan, the script dies because Connect-NcController fails to return anything.

 

I've peppered debugging write-host/logging statements everywhere can I can't for the life of me figure out why this works perfectly when NOT run from within SRM.

 

Surely someone else has done something with SRM and the PSTK here?  Any pointers?  I've been beating my head against the wall for quite some time on this.  Thanks a lot.

3 REPLIES

Re: Help with NetApp PowerShell Toolkit in external script called by VMware SRM

Hello @iehrenwaldHBG,

 

When you say the Connect-NcController cmdlet fails to return anything...you mean, literally, nothing?  Any error messages?  What is the contents of the varuable $global:CurrentNcController after the connection attempt?  Does your logging return anything?

 

In doing a bit of testing, when I assign the Connect-NcController output to a variable, the value is empty/null when the connection fails (e.g. because of incorrect credentials).

 

I listed some ways to store credentials for scripts at the bottom of this blog post, perhaps one of those ways will work for you?

 

Andrew

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

Re: Help with NetApp PowerShell Toolkit in external script called by VMware SRM

Also, you can capture all output of the script using the Start-Transcript cmdlet...

 

Start-Transcript -Path C:\logs\testme.log

$ClusterConn = Connect-NcController -Name $Cluster -Vserver $Vserver -Credential $Credential

Stop-Transcript

This will help capture errors output to the "console" (like below) that wouldn't normally be captured...

 

2018-01-05 11_38_33-Windows PowerShell ISE.png

 

Andrew

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

Re: Help with NetApp PowerShell Toolkit in external script called by VMware SRM

Oh, for crying out loud... (that's the G rated version of what I actually said).

 

Thank you for Start-Transcript/Stop-Transcript, I did not know about it.  It has pointed out exactly the problem.  The PsModulePath for the user running this script through SRM apparently does not get populated with "C:\Program Files (x86)\NetApp\NetApp PowerShell Toolkit\Modules\".  I appended it that env. var and it works now.  Boy do I feel dumb.

 

Thanks so much for the clue-bat to the back of the head.

 

Forums