Microsoft Virtualization Discussions

Using Powershell to set Multiple timed.servers with variables

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!


Re: Using Powershell to set Multiple timed.servers with variables

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.

Re: Using Powershell to set Multiple timed.servers with variables

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


Re: Using Powershell to set Multiple timed.servers with variables



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="" version="1.21">


ZAPI Results:


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


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 = ",,"
[String]$command = "options timed.servers $servers"
   Invoke-NaSsh -Command $command -ErrorAction Stop
   Write-Host "Executed Command: $command"   
   Write-Warning -Message $("Failed Executing Command: $command. Error " + $_.Exception.Message)


Hope that helps



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

Re: Using Powershell to set Multiple timed.servers with variables

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

Cloud Volumes ONTAP
Review Banner
All Community Forums