Enter-PSSession error

This topic contains 3 replies, has 3 voices, and was last updated by  Anthony Ngari 2 months, 2 weeks ago.

  • Author
  • #32640

    Ed O’Connor

    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 

    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

    Mark Hammonds

    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


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


    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

    Ed O’Connor

    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.

  • #90602

    Anthony Ngari

    Where could I be going wrong? Someone help.

    PS C:\WINDOWS\system32> Test-WsMan sylvia

    wsmid : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
    ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
    ProductVendor : Microsoft Corporation
    ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 3.0

    PS C:\WINDOWS\system32> Get-Item wsman:\localhost\client\trustedhosts

    WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Client

    Type Name SourceOfValue Value
    —- —- ————- —–
    System.String TrustedHosts sylvia, SERVER

    PS C:\WINDOWS\system32> Restart-Service WinRM
    PS C:\WINDOWS\system32> Enter-PSSession -ComputerName SYLVIA -Credential sylvia munguti
    Enter-PSSession : A positional parameter cannot be found that accepts argument 'munguti'.
    At line:1 char:1
    + Enter-PSSession -ComputerName SYLVIA -Credential sylvia munguti
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Enter-PSSession], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.EnterPSSessionCommand

You must be logged in to reply to this topic.