Microsoft Virtualization Discussions

Using Powershell to set Multiple timed.servers with variables

kramanella
5,760 Views

Having an issue using PowerShell to set 3 timed.servers which are defined in a variable. 

Running the commands:

 

$TimeServers = "IPaddress1,IPaddress2,IPaddress3"

Set-NaOption -OptionName timed.servers -OptionValue $TimeServers

 

Thanks in advance!

1 ACCEPTED SOLUTION

Aparajita
5,271 Views

Ahh, from Matt's observations and my own experiments, this looks like a bug in the zapi.

 

The first time I try setting multiple time servers, the zapi reports an error but sets it correctly none-the-less. If I repeat the same zapi call one more time, the call returns success. Same behavior is repeated when using the PSTK cmdlets as well - since they internally call the zapi.

 

Another alternate (to Matt's) workaround is to run the Set-NaOption with ErrorAction set as 'SilentlyContinue' and then use the Get-NaOption to check if timeserver was set correctly. If not set correctly, the script should throw an error.

 

View solution in original post

4 REPLIES 4

Aparajita
5,717 Views

What is the error you see?

 

I suspect if you initialize the string as $timeServers = '"IP1,IP2,IP3"(note the value of the string becomes "IP1,IP2,IP3" and that value is enclosed in single '), it will work.

kramanella
5,658 Views

So my goal is to only change one variable in one location in the script, as a result I have nested variables. Here's a more complete view into what I'm trying to accomplish:

 

# this is the only variable to change

$subnet = "xx" 

 

$TimeServers = "xxx.xx.$subnet.50,xxx.xx.$subnet.51,xxx.xx.$subnet.2"

Set-NaOption -OptionName timed.servers -OptionValue $TimeServers

 

The output of Write-Host $TimeServers looks good, 3 comma seperated ip addresses with

 

Here's the error message when the script runs:

Set-NaOption : Unable to set option: timed.servers
At P:\My Documents\WindowsPowerShell\timed_servers.ps1:57 char:1
+ Set-NaOption -OptionName timed.servers -OptionValue $TimeServers
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (xxx.xx.xx.xx:NaController) [Set-NaOption], EAPIERROR
+ FullyQualifiedErrorId : ApiException,DataONTAP.PowerShell.SDK.Cmdlets.Options.SetNaOption

 

mbeattie
5,563 Views

Hi,

 

The Set-NaOption CmdLet -optionvalue parameter expects a string and it shouldn't matter if that's a comma delimited string containing multiple IP Addresses. I noticed that whilst the cmdlet thows an error it does actually set the option value for all servers so this seems like it could be a bug (IMO). It might be possible to invoke the API using "Invoke-NaSystemApi" but I checked the ZAPI and noticed this also fails using ZExplore from the SDK:

 

ZAPI Request:

 

<?xml version="1.0" encoding="UTF-8"?>
<netapp  xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <options-set>
    <name>timed.servers</name>
    <value>192.168.100.10,192.168.100.11,192.168.100.12</value>
  </options-set>
</netapp>

 

ZAPI Results:

 

<?xml version='1.0' encoding='UTF-8' ?>
<netapp version='1.1' xmlns='http://www.netapp.com/filer/admin'>
    <!-- Output of options-set [Execution Time: 8610 ms] -->
    <results reason='Unable to set option: timed.servers' errno='13001' status='failed'>
        <cluster-constraint>same_preferred</cluster-constraint>
        <cluster_constraint>same_preferred</cluster_constraint>
        <message>1 entry was deleted.
</message>
    </results>
</netapp>

 

So i think the options are either using the "Set-NaOption" cmdlet with the -SilentlyContinue parameter or the "Invoke-NaSsh" cmdlet with -ErrorAction stop.

As a work around i'd recommend something like:

 

[String]$servers = "192.168.100.10,192.168.100.11,192.168.100.12"
[String]$command = "options timed.servers $servers"
Try{
   Invoke-NaSsh -Command $command -ErrorAction Stop
   Write-Host "Executed Command: $command"   
}Catch{
   Write-Warning -Message $("Failed Executing Command: $command. Error " + $_.Exception.Message)
}

 

Hope that helps

 

/matt

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

Aparajita
5,272 Views

Ahh, from Matt's observations and my own experiments, this looks like a bug in the zapi.

 

The first time I try setting multiple time servers, the zapi reports an error but sets it correctly none-the-less. If I repeat the same zapi call one more time, the call returns success. Same behavior is repeated when using the PSTK cmdlets as well - since they internally call the zapi.

 

Another alternate (to Matt's) workaround is to run the Set-NaOption with ErrorAction set as 'SilentlyContinue' and then use the Get-NaOption to check if timeserver was set correctly. If not set correctly, the script should throw an error.

 

Public