Enter-PSSession error

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.

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.

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.

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