Uploaded image for project: 'Modules'
  1. Modules
  2. MODULES-1996

PowerShell module doesn't recognize elseif

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • None
    • None
    • powershell
    • Windows
    • 2

    Description

      Originally reported at https://github.com/puppetlabs/puppetlabs-powershell/issues/51

      I'm experiencing some weird behavior with the powershell module. I'm using version 3.7.5 on the master and agent. The agent is a Windows 2012 R2 server with powershell 4.0. I have the following template to set the A record on a Microsoft DNS server.

      $dnsserver = "<%= @dns_server %>"
      $containerName = "<%= @container_name %>"
      $recordName = "<%= @record_name %>"
      $userName = "<%= @user_name %>"
      $password = "<%= @password %>"
      $TTL = '<%= @ttl %>'
      $recordType = "<%= @record_type %>"
       
      if ($recordType.ToLower() -eq "a")
          {$_recordType = "MicrosoftDNS_AType"}
      elseif ($recordType.ToLower() -eq "cname")
          {$_recordType = "MicrosoftDNS_CNAMEType"}
      $DNSAdmin = New-ObJect System.Management.Automation.PSCredential ($userName, (ConvertTo-SecureString $password -AsPlainText -Force))
      $record = Get-WmiObject -ComputerName $dnsserver -Namespace "root\MicrosoftDNS" -Class $_recordType -Filter "ContainerName='$containerName' AND OwnerName='$recordName'" -Credential $DNSAdmin
      $ipaddress = (new-object net.webclient).DownloadString('http://169.254.169.254/latest/meta-data/local-ipv4')
       
      if ($record.IPAddress -eq $ipaddress -and $record.TTL -ne $TTL)
          {$record.Modify($TTL -as [uint32])}
      elseif ($record.IPAddress -ne $ipaddress)
          {$record.Modify($record.TTL, $ipaddress)}
      

      I receive the following error when the script runs...

      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: elseif : The term 'elseif' is not recognized as the name of a cmdlet, function, script file, or operable program. Chec
      k the spelling of the name, or if a path was included,
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: verify that the path is correct and try again.
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: At line:1 char:1
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: + elseif ($recordType.ToLower() -eq "cname")
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: + ~~~~~~
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:     + CategoryInfo          : ObjectNotFound: (elseif:String) [], CommandNotFoundException
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:     + FullyQualifiedErrorId : CommandNotFoundException
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: $_recordType = "MicrosoftDNS_CNAMEType"
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: elseif : The term 'elseif' is not recognized as the name of a cmdlet, function, script file, or operable program. Chec
      k the spelling of the name, or if a path was included,
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: verify that the path is correct and try again.
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: At line:1 char:1
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: + elseif ($record.IPAddress -ne $ipaddress)
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: + ~~~~~~
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:     + CategoryInfo          : ObjectNotFound: (elseif:String) [], CommandNotFoundException
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:     + FullyQualifiedErrorId : CommandNotFoundException
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns:
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: $record.Modify($record.TTL, $ipaddress)
      Notice: /Stage[main]/Modify_dns/Exec[modifydns]/returns: executed successfully
      Notice: Finished catalog run in 22.56 seconds
      

      The template file is in ANSI, DOS/Win line endings, and no tabs. I'm not sure what the problem may be.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              rob Rob Reynolds
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support