locked
General Script help RRS feed

  • Question

  • Can someone help me with the powershell commands.
    basically what i want to do is that -

    I have multiple computers on the same network - LAN
    I want to enter them and make them download a file and execute them.


    Enter-PSSession -ComputerName xxx

    then now [script for making them download a file from direct link]
    waits 
    [script for executing the file]
    Exit-PSSession

    What I have came up with but not really this

    Enter-PSSession -ComputerName (XX)
    $Source = '(XX)'
    $Destination = "$env:temp\"
    Invoke-WebRequest -uri $Source -OutFile $Destination
    Unblock-File $Destination




    Monday, November 30, 2015 4:17 PM

Answers

  • Your source variable needs to be a URL, as you're likely aware. Your $Destination variable needs to include a file name and file extension, such as file.txt, or you'll get an access denied error when trying to use the -OutFile parameter. Make $Destination "$env:temp\file.txt" and try again. Everything else seems as though it would work.
    • Proposed as answer by Elaine Jing Tuesday, December 15, 2015 10:08 AM
    • Marked as answer by Elaine Jing Friday, December 18, 2015 3:22 AM
    Monday, November 30, 2015 4:38 PM
  • you could use psexec.exe to run the file remotely.

    https://technet.microsoft.com/en-us/sysinternals/pstools.aspx?f=255&MSPPError=-2147217396

    here is an example. this downloads the file to the remote machine using your computer, then uses psexec to open/run the file on the remote machine. for more help, run psexec.exe /? after downloading the tools above

    $computer = $env:COMPUTERNAME
    $Source = 'https://goo.gl/L7VLBp'
    $Destination = "\\$computer\c$\temp\image.jpg"
    Invoke-WebRequest -uri $Source -OutFile $Destination
    C:\pstools\PsExec.exe -i \\$computer cmd /c start $Destination

    With PowerShell w use Enter-PsSession to get remote access.  It is more reliable and more secure.  PsExec is likely blocked on most corporate networks.

    We can also use WMI to remotely execute  NON-GUI file. Most corporate network will not allow remote downloads so you will need to download locally and copy to the remote systems.


    \_(ツ)_/

    • Proposed as answer by Elaine Jing Tuesday, December 15, 2015 10:05 AM
    • Marked as answer by Elaine Jing Friday, December 18, 2015 3:22 AM
    Monday, December 14, 2015 4:29 AM

All replies

  • Your source variable needs to be a URL, as you're likely aware. Your $Destination variable needs to include a file name and file extension, such as file.txt, or you'll get an access denied error when trying to use the -OutFile parameter. Make $Destination "$env:temp\file.txt" and try again. Everything else seems as though it would work.
    • Proposed as answer by Elaine Jing Tuesday, December 15, 2015 10:08 AM
    • Marked as answer by Elaine Jing Friday, December 18, 2015 3:22 AM
    Monday, November 30, 2015 4:38 PM
  • you could use psexec.exe to run the file remotely.

    https://technet.microsoft.com/en-us/sysinternals/pstools.aspx?f=255&MSPPError=-2147217396

    here is an example. this downloads the file to the remote machine using your computer, then uses psexec to open/run the file on the remote machine. for more help, run psexec.exe /? after downloading the tools above

    $computer = $env:COMPUTERNAME
    $Source = 'https://goo.gl/L7VLBp'
    $Destination = "\\$computer\c$\temp\image.jpg"
    Invoke-WebRequest -uri $Source -OutFile $Destination
    C:\pstools\PsExec.exe -i \\$computer cmd /c start $Destination

    Monday, December 14, 2015 3:42 AM
  • you could use psexec.exe to run the file remotely.

    https://technet.microsoft.com/en-us/sysinternals/pstools.aspx?f=255&MSPPError=-2147217396

    here is an example. this downloads the file to the remote machine using your computer, then uses psexec to open/run the file on the remote machine. for more help, run psexec.exe /? after downloading the tools above

    $computer = $env:COMPUTERNAME
    $Source = 'https://goo.gl/L7VLBp'
    $Destination = "\\$computer\c$\temp\image.jpg"
    Invoke-WebRequest -uri $Source -OutFile $Destination
    C:\pstools\PsExec.exe -i \\$computer cmd /c start $Destination

    With PowerShell w use Enter-PsSession to get remote access.  It is more reliable and more secure.  PsExec is likely blocked on most corporate networks.

    We can also use WMI to remotely execute  NON-GUI file. Most corporate network will not allow remote downloads so you will need to download locally and copy to the remote systems.


    \_(ツ)_/

    • Proposed as answer by Elaine Jing Tuesday, December 15, 2015 10:05 AM
    • Marked as answer by Elaine Jing Friday, December 18, 2015 3:22 AM
    Monday, December 14, 2015 4:29 AM