psexec

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 3 months ago.

  • Author
    Posts
  • #6076

    by graybin at 2013-04-17 12:33:14

    I am trying to execute icacls on a remote computer, but I keep getting error messages.

    PsExec could not start icacls \\It171oafs-oa02\CSVD_SHARE\ADC on ltso027sab:
    The system cannot find the path specified.

    I used

    $RemoteServer = "\\someserver"
    $Name = "Security Group"
    $Path = "\\randomserver\share\folder path"
    $Rights = '"(CI)(R,X)"'
    $Cred = Get-Credential
    $Password = $Cred.GetNetworkCredential().password
    $Password = @"
    "$Password"
    "@
    $UserName = $Cred.UserName
    $UserName = @"
    "$UserName"
    "@
    $Path = @"
    "$Path"
    "@

    $Command = "icacls $path /grant $Name" + ":$Rights"
    psexec $RemoteServer -u $UserName -p $Password $Command

    by poshoholic at 2013-04-17 14:20:19

    I think your path needs to be quoted. Take a look at this part of your script, in particular what the string looks like once you create it:
    $Command = "icacls $path /grant $Name" + "]
    If you show the value of $Command after you invoke that line, you'll see something like this (manually substituted):
    icacls \\randomserver\share\folder path /grant Security Group:"(CI)(R,X)"
    I think what you really want is something like this instead:
    icacls "\\randomserver\share\folder path" /grant Security Group:"(CI)(R,X)"
    Also, shouldn't "Security Group" be quoted as well? I'm not a heavy user of icacls, but the spaces are what concerned me the most when I read this.

    Lastly, you don't need to do string arithmetic to build your command string. To deal with the colon character causing issues when PowerShell tries to resolve the string, just put your variable names inside curly braces. I've gotten into the habit of always doing this because it allows me to have variables inside strings even when they are adjacent to colons or other characters. That would make your $Command variable assignment look like this:
    # Note: I added double-quotes around the $path variable in the string here so that you could leave it unquoted in your variable assignment
    $Command = "icacls ""${path}"" /grant ${Name}]

    by graybin at 2013-04-18 04:58:40

    I used:
    $Path = "\\someserver\path with a space"
    $RemoteServer = "\\anotherserver"
    $Command = "icacls ""${path}"" /grant ${Name}:${Rights}"

    $Command
    icacls "\\someserver\path with a space" /grant NEWGROUP:"(OI)(CI)(R,RX)"

    psexec $RemoteServer -u $UserName -p $Password $Command
    And got the following results:
    PsExec could not start icacls \\someserver\path on anotherserver:
    The system cannot find the path specified.

    by happysysadm at 2013-04-18 05:18:30

    Just a little question. You have icacls on your remote system? Is it in the path?
    If not, try to add the -c switch to copy the executable to the remote system before executing.
    Carlo

    by poshoholic at 2013-04-18 06:30:08

    Reading the results seems to indicate quite clearly that the path is incorrect. Look at the error message you shared:

    [quote]PsExec could not start icacls \\someserver\path on anotherserver[/quote]

    That definitely seems like the issue is related to the command line that is being built. If you were to enter the psexec command manually with that same string, you would probably get the same error, indicating that PowerShell isn't the problem. You should probably work out what the syntax should be if you were to invoke the command directly, and then modify your script so that it generates a command in that same format.

    by MasterOfTheHat at 2013-04-19 07:09:18

    [quote="graybin"]I used:
    $Path = "\\someserver\path with a space"
    $RemoteServer = "\\anotherserver"
    $Command = "icacls ""${path}"" /grant ${Name}:${Rights}"

    $Command
    icacls "\\someserver\path with a space" /grant NEWGROUP:"(OI)(CI)(R,RX)"

    psexec $RemoteServer -u $UserName -p $Password $Command
    And got the following results:
    PsExec could not start icacls \\someserver\path on anotherserver:
    The system cannot find the path specified.
    [/quote]
    Lines 5 and 6 don't make sense...

    What do you get if you run this?
    $Path = "\\someserver\path with a space"
    $RemoteServer = "\\anotherserver"
    $Command = "icacls ""${path}"" /grant ${Name}:${Rights}"

    $Command
    Is that what line 6 is supposed to be showing?

You must be logged in to reply to this topic.