title: Powershell 4.0 Remoting DNS module from Win 7 PC to Win 8.1 PC
body: <p>I have a strange one here, can't find anything on the Google hoping someone can help.</p>
  
  <p>A little background, I'll try to keep it short.</p>
  
  <p>I run a script that grabs all PC objects in my domain, pings them - if it gets an IP address back it connects to remote registry by IP, pulls back PC name. Also runs NBTSTAT -a and NBTSTAT -A and gives me three computer name reference points to compare to the computer name in AD and if they comback mismatched this tells me if the DNS record is bad. So I want to be able to automate deleting the DNS record on the fly in the script. So far so good. </p>
  
  <p>My company standard is Windows 7 SP 1, I have installed WMF 4.0 so Powershell is 4.0. I also have a non-company standard Windows 8.1 PC, which contains the DNS module Powershell 4.0 on Win 7 does not. The script I'm running calls Excel and populates data for each PC in the collection from AD, works fine when running from my Windows 7 PC's, but does not work on the Windows 8.1 PC for unknown reason which i have been unable to correct. So I have to run the script on my Win 7 PC's to work correctly.</p>
  
  <p>After searching for ways to delete the DNS record without using the new modules only available on the 8.1 box, I could find nothing that was fairly easy and straightforward so I came up with the idea of using PSRemoting to create a session from within the script running on the Win 7 PC to the 8.1 PC, then perform the DNS portion remotely on the 8.1 PC before returning to the script on the Win 7 PC and carrying on.</p>
  
  <p>I decided to start with a simple query to make sure this would work. If I run the following test script locally on the 8.1 PC, works great and returns the data:</p>
  
  <pre><code>$DNSInfo = Get-DnsServerResourceRecord -ComputerName "DNS.SVR.IP.ADDR" -ZoneName "DNSZone.mycompany.com" -Name PCName
  $HostName = $DNSInfo.HostName
  $RecordType = $DNSInfo.RecordType
  $RecordClass = $DNSInfo.RecordClass
  $TimeToLive = $DNSInfo.TimeToLive
  $Timestamp = $DNSInfo.Timestamp
  $IPAddress = $DNSInfo.RecordData.IPv4Address.IPAddressToString
  
  Write-Host $HostName
  Write-Host $RecordType
  Write-Host $RecordClass
  Write-Host $DNSInfo.RecordData.IPv4Address.IPAddressToString
  
  Produces:
  
  PS C:\WINDOWS\system32&gt; C:\Powershell\DNS\DNS_testLocal.ps1
  PCName
  A
  IN
  PC.Name.IP.ADDR
  </code></pre>
  
  <p>So far so good. However, when I run the following script from my Win 7 PC, it fails and gives an error. Exact same scriptblock, same user account logged into each PC.</p>
  
  <pre><code>$PCSession = New-PSSession -ComputerName WIN81PC
  Invoke-Command -Session $PCSession -Scriptblock {
                                                  $DNSInfo = Get-DnsServerResourceRecord -ComputerName "DNS.SVR.IP.ADDR" -ZoneName "DNSZone.mycompany.com" -Name PCName
                                                  $HostName = $DNSInfo.HostName
                                                  $RecordType = $DNSInfo.RecordType
                                                  $RecordClass = $DNSInfo.RecordClass
                                                  $TimeToLive = $DNSInfo.TimeToLive
                                                  $Timestamp = $DNSInfo.Timestamp
                                                  $IPAddress = $DNSInfo.RecordData.IPv4Address.IPAddressToString
                                                  }
  
  Write-Host $HostName
  Write-Host $RecordType
  Write-Host $RecordClass
  Write-Host $DNSInfo.RecordData.IPv4Address.IPAddressToString
  
  Produces the following error:
  
  PS C:\Windows\system32&gt; C:\Powershell\DNS\DNS_testremote.ps1
  Failed to get the zone information for DNSZone.mycompany.com on server DNS.SVR.IP.ADDR.
      + CategoryInfo          : PermissionDenied: (DNSZone.mycompany.com:root/Microsoft/...rResourceRecord) [Get-DnsServerResourceRecord], CimException
      + FullyQualifiedErrorId : WIN32 5,Get-DnsServerResourceRecord
      + PSComputerName        : WIN81PC
  </code></pre>
  
  <p>I realize that the "sending" PC in this case, the Win 7 PC does not have the DNS module available to it, but isn't the remoting session simply passing on the code to the 8.1 PC where it should execute properly as it does when running the exact same script block locally? And since the same user account is logged into both PC's, how could this be a rights issue? Any feedback would be appreciated.</p>