Enter-PSSession error

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Ed O'Connor Ed O’Connor 1 year, 7 months ago.

  • Author
    Posts
  • #32640
    Profile photo of Ed O'Connor
    Ed O’Connor
    Participant

    I posted yesterday and received some excellent assistance getting a powershell script working. Today I have built upon that functionality and trying make it so the script will run against multiple computers. Everything works fine if I use 'invoke-command' to connect to the remote servers. When I try and use 'Enter-PSSession' I get the following error:

    PS>TerminatingError(Enter-PSSession): "A positional parameter cannot be found that accepts argument '

    Here is my script:

    #Script to identify all zones on a DNS server and enable zone transfers
    
    #Creates a log file of Zone Transfer setting prior to any changes
    
    Start-Transcript .\ZoneTransferInfo.txt
    
    #Specifies the Domain Controllers to run
    
    #$DomainControllers =  Get-Content .\DomainControllers.txt
    
    foreach ($DC in $DomainControllers) {
    
    Write-Output "*********************************************************************************************************"
    Write-Output " "
    Write-Output $DC
    Write-Output " "
    
    Enter-PSSession -Computername $DC {
    
    #Prints the Current Zone Transfer settings
    
    Write-Output " "
    Write-Output "DNS Zone Transfer Settings prior to changes"
    Write-Output " "
    
    Get-DNSServerZone | select-object ZoneName, SecureSecondaries
    
    #Creates the collection containing the ZoneNames and then changes the setting to TransferAnyServer
    
    Write-Output "***************************************************************************"
    Write-Output " "
    Write-Output "Making Changes"
    Write-Output " "
    
    $NoSecureSecondaries = Get-DNSServerZone | 
    select -expand ZoneName
    
     foreach ($zonename in $NoSecureSecondaries) {
      Try {
    Set-DNSServerPrimaryZone -Name "$zonename" -SecureSecondaries "TransferAnyServer" -PassThru
    } Catch {
      Write-Output $zonename "Zone Transfer Settting cannot be changed"
    	} 
    }
    
    Write-Output " "
    Write-Output "End of changes"
    Write-Output " "
    
    #Prints the Zone Transfer settings after the changes have been applied
    
    Write-Output "***************************************************************************"
    Write-Output " "
    Write-Output "DNS Zone Transfer Settings after changes"
    Write-Output " "
    
    Get-DNSServerZone | select-object ZoneName, SecureSecondaries 
    
    }
    }
    
    Stop-Transcript
    
    Exit
    

    I would like to use 'Enter-PSSession' as I am keeping a log of the session and when I use Invoke-Command there is a lot of noise and the log is not as clean data wise.

    Any ideas and suggestions are greatly appreciated.

    Thanks in advance.

  • #32642
    Profile photo of Mark Hammonds
    Mark Hammonds
    Participant

    are you trying to run a script block? – https://technet.microsoft.com/en-us/library/hh849717.aspx

    $s = New-PSSession -ComputerName (Get-Content Servers.txt) -Credential Domain01\Admin01 -ThrottleLimit 16
    PS C:\>Invoke-Command -Session $s -ScriptBlock {Get-Process PowerShell} -AsJob

    Also read this about remote jobs and how to receive jobs

    https://technet.microsoft.com/en-us/library/hh847805.aspx

    another good thing to read up on it the fan out method

    http://blogs.technet.com/b/heyscriptingguy/archive/2012/07/25/an-introduction-to-powershell-remoting-part-three-interactive-and-fan-out-remoting.aspx

    There are two primary PowerShell Remoting usage paradigms for IT professionals: interactive and fan-out. Interactive remoting is used when I need to interact with a remote computer as if I was sitting directly in front of the system, logged into the console. Fan-out remoting is used when I have a single command or script that I want to run on a group of computers. It could be two systems, or two thousand systems. Whenever I need a command to efficiently execute on a large number of systems, fan-out is the way to go.

  • #32649
    Profile photo of Ed O'Connor
    Ed O’Connor
    Participant

    Thanks, I will look at that. I changed the script to use 'Invoke-Command' and filtered out some of the info that was a bit verbose. The transcript/log is not as clean as I like but acceptable.

You must be logged in to reply to this topic.