Share via


Missing ')' in method call.

Question

Thursday, January 28, 2010 9:39 PM

If I run the following from within a powershell command prompt, I get success.

$objuser = [ADSI] ("WinNT://sccmtest/PDCSCCMSQL$");$objgroup = [ADSI] ("WinNT://sccmtest/BITS Throttling");$objgroup.PSBase.Invoke("Add",$objuser.PSBase.Path)

If I run the following from a regular command prompt, I get a failure.

powershell.exe -command $objuser = [ADSI] ("WinNT://sccmtest/PDCSCCMSQL$");$objgroup = [ADSI] ("WinNT://sccmtest/BITS Throttling");$objgroup.PSBase.Invoke("Add",$objuser.PSBase.Path)

Which returns the following:

C:\Documents and Settings\Administrator>powershell.exe -command $objuser = [ADSI
] ("WinNT://sccmtest/PDCSCCMSQL$");$objgroup = [ADSI] ("WinNT://sccmtest/BITS Th
rottling");$objgroup.PSBase.Invoke(Add,$objuser.PSBase.Path)
Missing ')' in method call.
At line:1 char:128

  • $objuser = [ADSI] (WinNT://sccmtest/PDCSCCMSQL$);$objgroup = [ADSI] (WinNT://
    sccmtest/BITS Throttling);$objgroup.PSBase.Invoke( <<<< Add,$objuser.PSBase.Pat
    h)
        + CategoryInfo          : ParserError: (CloseParenToken:TokenId) [], Paren
       tContainsErrorRecordException
        + FullyQualifiedErrorId : MissingEndParenthesisInMethodCallh)

What am I missing that would allow the script to work within the powershell, but not from a regular command prompt?

All replies (5)

Thursday, January 28, 2010 9:56 PM âś…Answered

Try this (took out some double quotes to reduce potential parsing issues):

powershell.exe -command "& {$objuser = [ADSI]'WinNT://sccmtest/PDCSCCMSQL$'; $objgroup = [ADSI]'WinNT://sccmtest/BITS Throttling'; $objgroup.PSBase.Invoke('Add', $objuser.PSBase.Path) }"

Thanks,
-Lincoln


Thursday, January 28, 2010 9:47 PM

Yes, using quotes when calling from powershell.exe can be troublesome.  How about calling a .ps1 instead with the commands in it?


Thursday, January 28, 2010 9:54 PM

If you really don't want to use a script, try running it with the command enclosed in single quotes.  My guess is command interpreter is messing with your strings before they get passed to PowerShell.


Thursday, January 28, 2010 10:23 PM

Here's a blog that explains my end goal, and I don't think I can accomplish what I'm trying to do with a .ps1.

http://myitforum.com/cs2/blogs/sthompson/archive/2010/01/28/how-to-add-sms-2003-configmgr-2007-computers-in-a-collection-to-an-active-directory-security-group.aspx

NET GROUP can only be ran from a Domain Controller, and in my live environment, my SQL server is not a domain controller, therefore NET GROUP wont work.  I need to use a different command line in my SQL script to add an array of hostnames into the AD group.


Thursday, January 28, 2010 10:30 PM

Thanks so much Lincoln.  I cannot believe how fast that was!