Question about running DNSCmd.exe remotely using PSSession

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 3 years, 2 months ago.

  • Author
    Posts
  • #14460
    Profile photo of Chris Stella
    Chris Stella
    Participant

    Help! I'm fairly new to PowerShell so bear with me if this is an obvious fix, but I haven't found an answer yet. I'm trying to use the DNSCmd.exe command to add a DNS entry on a remote computer. I'm using PowerShell to run the command remotely using PSSession.

    The issue is, I get the REMOTE_ACCESS_DENIED error from DNSCmd.exe when I run the command remotely with PowerShell, but it works if I'm actually logged into the remote computer and run the command locally using the same credentials.

    Attempting via PSSession (From Win 8):

    PS D:\> Enter-PSSession -Credential $creds SERVER1
    
    [SERVER1]: PS C:\windows\system32> dnscmd.exe DNSSERVER /recordadd ZONE dnstest1008 A 192.168.1.100
    
    Command failed:  ERROR_ACCESS_DENIED     5    0x5

    ——————————————–
    Performed on SERVER1 (Server 2012):

    PS C:\windows\system32> dnscmd.exe DNSSERVER /recordadd ZONE dnstest1008 A 192.168.1.100
    
    Add A Record for dnstest1008.ZONE at ZONE
    Command completed successfully.
  • #14461
    Profile photo of Chris Stella
    Chris Stella
    Participant

    Oh gosh. Please forgive my formatting.

  • #14473
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Looks like you're running into the "second hop" issue there, trying to access another remote server via a PSSession. Check out the "Secrets of PowerShell Remoting" ebook from https://powershell.org/ebooks/ ; there's a section on how you can get around that problem by enabling CredSSP.

You must be logged in to reply to this topic.