Welcome Forums General PowerShell Q&A Bulk Update Microsoft DNS (Multi Zone, Multi Data)

Viewing 1 reply thread
  • Author
    • #170815
      Topics: 1
      Replies: 0
      Points: 12
      Rank: Member

      Hi All,


      What am I doing wrong with the code below?

      write-host $data
      $data = Import-CSV "C:\scripts\Data.csv" -header ZoneName,Name,DescriptiveText
      ForEach-Object { 
      Add-DnsServerResourceRecord -ZoneName $data.ZoneName -Txt -Name $data.Name -DescriptiveText $data.DescriptiveText

      CSV Example:


      I get the following error:

      Add-DnsServerResourceRecord : Cannot process argument transformation on parameter 'ZoneName'. Cannot convert value to type System.String.

      Tried playing around with [string] arguments but I’m doing something wrong.
      I’m not great with PS so any help is welcome!

      Thank you

    • #170854
      Topics: 0
      Replies: 42
      Points: 404
      Team MemberHelping Hand
      Rank: Contributor

      I think you’ll want to provide an InputObject for the foreach, and then use the inbuilt $_/$PSItem variable to operate on each item rather than passing the entire $Data object each time.

      $Data = Import-CSV "C:\scripts\Data.csv" -Header ZoneName,Name,DescriptiveText
      Write-Host "Data contains '$($Data.Count)' items"
      $Data | ForEach-Object {
          Add-DnsServerResourceRecord -ZoneName $_.ZoneName -Name $_.Name -DescriptiveText $_.DescriptiveText
Viewing 1 reply thread
  • The topic ‘Bulk Update Microsoft DNS (Multi Zone, Multi Data)’ is closed to new replies.