Run non-powershell command on remote computer.

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Don Jones Don Jones 7 months ago.

  • Author
    Posts
  • #38586
    Profile photo of Kenny Yarbrough
    Kenny Yarbrough
    Participant

    I'm attempting to automate some Treesize reports using powershell. I can run the report fine from the server, but if I try to do this remotely in a scriptblock it doesn't run and I feel like I must be missing something small and silly.

    Here is what I'm doing which seems to give me the correct syntax, but doesn't do anything.
    $target = computer2
    $executable = "c:\program files (x86)\JAM Software\TreeSize Professional\treesize.exe"
    $command = "$executable /Date /HTML `"\\$target\c$\disk.html`" `"\\$target\c$`""
    invoke-command -computername computer2 -scriptblock {$executable}

    Any tips on how to get this working?

  • #38589
    Profile photo of Edmond Yee
    Edmond Yee
    Participant

    You are trying to execute $executable in your invoke-command statement, but I think you mean to execute $command.

  • #38638
    Profile photo of Don Jones
    Don Jones
    Keymaster

    You're likely to run into a problem asking a remote session to access a UNC – this is the double hop problem, and it's explained in "Secrets of PowerShell Remoting."

You must be logged in to reply to this topic.