PowerCLI

 View Only
  • 1.  Start-Process : A positional parameter cannot be found that accepts argument

    Posted Jul 07, 2020 02:37 PM

    Hi,

    I am having trouble executing this command from a batch file on few of the VMs and I am getting below error.

    Please help

    Command

    Powershell.exe -noprofile -executionpolicy bypass -command "&{start-process powershell -ArgumentList -noprofile 'Get-DnsClientServerAddress | where {$_.ServerAddresses -contains 192.168.15.5} | Set-DnsClientServerAddress -ServerAddresses 192.168.5.100,192.168.5.101' -Verbose -Confirm:$false; ipconfig /flushdns; ipconfig /flushdns; Clear-DnsClientCache; Register-DnsClient -verb RunAs}"

    Error

    Start-Process : A positional parameter cannot be found that accepts argument 'Get-DnsClientServerAddress | where

    {$_.ServerAddresses -contains 192.168.15.5} | Set-DnsClientServerAddress -ServerAddresses 192.168.5.100,192.168.5.101'.

    At line:1 char:3

    + &{start-process powershell -ArgumentList -noprofile 'Get-DnsClientSer ...

    +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException

        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand



  • 2.  RE: Start-Process : A positional parameter cannot be found that accepts argument

    Posted Jul 07, 2020 03:54 PM

    The ArgumentList parameter expects an array with arguments.

    I'm not sure what you are trying to do, but the following should get rid of the error.

    $code = @'

    $sProcess = @{

        FilePath = 'powershell.exe'

        ArgumentList = '-noprofile',

            '-verb runas',

            '-command "&{Get-DnsClientServerAddress | where {$_.ServerAddresses -contains 192.168.15.5} | Set-DnsClientServerAddress -ServerAddresses 192.168.5.100,192.168.5.101 -Verbose -Confirm:$false; ipconfig /flushdns; ipconfig /flushdns; Clear-DnsClientCache; Register-DnsClient}"'

    }

    Start-Process @sProcess

    '@


    powershell.exe -noprofile -executionpolicy bypass -command "&{$code}"



  • 3.  RE: Start-Process : A positional parameter cannot be found that accepts argument

    Posted Jul 07, 2020 04:24 PM

    LucD,

    I am trying to run script as .cmd file for DR Servers to update the DNS while performing the DR.

    Below is the script, which I am using.

    Currently I am getting the below error

    C:\DR>Powershell.exe -noprofile -executionpolicy bypass "&{start-process powershell -ArgumentList '-noprofile', '-verb r

    unas', '-command "  & {Get-DnsClientServerAddress   | where {$_.ServerAddresses -contains 192.168.15.5}   | Set-DnsClien

    tServerAddress -ServerAddresses 192.168.5.100,192.168.5.101 -Verbose -Confirm:$false; ipconfig /flushdns; ipconfig /flus

    hdns; Clear-DnsClientCache; Register-DnsClient}"' }"

    The string is missing the terminator: '.

        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

        + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

    '{Get-DnsClientServerAddress' is not recognized as an internal or external command,

    operable program or batch file.



  • 4.  RE: Start-Process : A positional parameter cannot be found that accepts argument

    Posted Jul 07, 2020 04:47 PM

    Did you try it like this?

    powershell.exe -noprofile -executionpolicy bypass -command "&{Start-Process -FilePath powershell.exe -ArgumentList '-noprofile','-verb RunAs','-command "&{Get-DnsClientServerAddress | where {$_.ServerAddresses -contains 192.168.15.5} | Set-DnsClientServerAddress -ServerAddresses 192.168.5.100,192.168.5.101 -Verbose -Confirm:$false; ipconfig /flushdns; ipconfig /flushdns; Clear-DnsClientCache; Register-DnsClient}"'}"


  • 5.  RE: Start-Process : A positional parameter cannot be found that accepts argument

    Posted Jul 07, 2020 04:56 PM

    Yes LucD.

    I am getting the below error

    The string is missing the terminator: '.

        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

        + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

    '{Get-DnsClientServerAddress' is not recognized as an internal or external command,

    operable program or batch file.



  • 6.  RE: Start-Process : A positional parameter cannot be found that accepts argument

    Posted Jul 07, 2020 06:16 PM

    It's a quoting issue.

    The following seems to work for me

    powershell.exe -noprofile -executionpolicy bypass -command "&{Start-Process -FilePath powershell.exe -ArgumentList '-noprofile','-command &{Get-DnsClientServerAddress | where {$_.ServerAddresses -contains 192.168.15.5} | Set-DnsClientServerAddress -ServerAddresses 192.168.5.100,192.168.5.101 -Verbose -Confirm:$false; ipconfig /flushdns; ipconfig /flushdns; Clear-DnsClientCache; Register-DnsClient}'}"


  • 7.  RE: Start-Process : A positional parameter cannot be found that accepts argument

    Posted Jul 08, 2020 04:45 AM

    Hi LucD,

    Now, I am not getting any error but DNS IP is not getting changed.

    If I execute the below command directly, DNS is getting changed. but when added with script, DNS is not getting change.

    Get-DnsClientServerAddress | where {$_.ServerAddresses -contains 192.168.15.5} | Set-DnsClientServerAddress -ServerAddresses 192.168.5.100,192.168.5.101 -Verbose -Confirm:$false



  • 8.  RE: Start-Process : A positional parameter cannot be found that accepts argument

    Posted Jul 08, 2020 05:07 AM

    You probably need elevation for the cmdlet to work.



  • 9.  RE: Start-Process : A positional parameter cannot be found that accepts argument

    Posted Jul 08, 2020 05:14 AM

    Yes LucD, I tried as below also, still no luck

    powershell.exe -noprofile -executionpolicy bypass -command "&{Start-Process -FilePath powershell.exe -ArgumentList '-noprofile','-command &{Get-DnsClientServerAddress | where {$_.ServerAddresses -contains 172.24.255.5} | Set-DnsClientServerAddress -ServerAddresses 172.25.255.5,172.25.255.6 -Verbose -Confirm:$false; ipconfig /flushdns; ipconfig /flushdns; Clear-DnsClientCache; Register-DnsClient -verb RunAs}'}"

    all the other commands work, but first command for changing the DNS still dont work. :smileysad:



  • 10.  RE: Start-Process : A positional parameter cannot be found that accepts argument

    Posted Jul 08, 2020 05:59 AM

    Your initial call to powershell.exe will not run elevated.