Using PowerShell to execute remote commands vs. executing PowerShell with PsExec ?

EnterpriseArchitect 5,116 Reputation points
2023-05-06T13:17:32.6233333+00:00

From my laptop, I am required to remotely execute some actions on a server that is not domain-joined and another that is domain-joined.

When it comes to non-AD domain joined computers, how can I accomplish the task?

Shall I use PsExec https://learn.microsoft.com/en-us/sysinternals/downloads/psexec or instead of the Invoke-Command script https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?

I would appreciate any assistance or suggestions you may have.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,317 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,182 questions
Windows Server Security
Windows Server Security
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Security: The precautions taken to guard against crime, attack, sabotage, espionage, or another threat.
1,776 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,449 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,287 questions
0 comments No comments
{count} votes

Accepted answer
  1. Konstantinos Passadis 17,456 Reputation points MVP
    2023-05-06T14:20:06.6133333+00:00

    Hello @EnterpriseArchitect !

    The main difference between PsExec and PowerShell remoting is that PsExec is a standalone tool that does not require any configuration or setup, while PowerShell remoting requires PowerShell to be installed and configured on both the local and remote computers.

    Another difference is that PsExec can only execute commands or scripts on the remote computer, while PowerShell remoting provides a full PowerShell session on the remote computer, allowing you to interact with the remote computer as if you were sitting in front of it.

    Overall, both PsExec and PowerShell remoting can be useful tools for remote management and automation, but PowerShell remoting provides a more powerful and flexible solution for managing remote computers, especially in large-scale environments.

    ALSO for Powershell Remote

    PowerShell Remoting is a powerful feature of PowerShell that allows you to execute commands and scripts on remote machines from your local machine. There are two methods to use PowerShell Remoting:

    1. Implicit Remoting:
    • This method allows you to import commands from a remote session to your local machine.
    • It requires you to have a remote session established with the target machine.
    • Once the session is established, you can use the imported commands just like any other local command.
    1. Explicit Remoting:
    • This method allows you to execute commands on a remote machine as if you were sitting in front of it.
    • It requires you to use the Invoke-Command cmdlet to execute a command/scriptblock on the remote machine.
    • The results are then returned to your local machine for processing.

    The main difference between the two methods is how the commands are executed on the remote machine. With implicit remoting, the commands are executed locally on the target machine and the results are returned to your local machine. With explicit remoting, the commands are executed on the remote machine and the results are returned to your local machine.


    The answer or portions of it have been assisted by AI Source: ChatGPT Subscription

    Kindly mark the answer as Accepted and Upvote in case it helped or post your feedback to help !

    Regards

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Konstantinos Passadis 17,456 Reputation points MVP
    2023-05-06T14:07:40.4966667+00:00

    Hello @EnterpriseArchitect !

    Yes, you can use PsExec to remotely execute actions on a non-AD domain joined computer. PsExec is a powerful command-line tool that enables you to run commands or launch applications on remote computers. It can be used to execute commands as a different user, interactively, or as a service.

    To use PsExec, you will need to download and install it on your local computer. Once installed, you can use the following command to remotely execute a command on the target computer:

    psexec \\computername command

    Replace "computername" with the name of the target computer and "command" with the command you want to execute. You will need to have administrative privileges on the target computer to use PsExec.

    Alternatively, you can use PowerShell's Invoke-Command cmdlet to remotely execute commands on a non-AD domain joined computer. Invoke-Command allows you to run commands on remote computers, even those that are not joined to a domain, using the WinRM protocol. Here's an example:

    Invoke-Command -ComputerName computername -Credential username -ScriptBlock { command }

    Replace "computername" with the name of the target computer, "username" with the name of an account that has administrative privileges on the target computer, and "command" with the command you want to execute.

    Both PsExec and Invoke-Command are powerful tools that can be used to remotely execute commands on non-AD _--domain joined computers. The choice between them depends on your specific requirements and preferences.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-7.3


    This answer or portions of it are assisted by AI of Source: ChatGPT Subscription

    Kindly mark the answer as Accepted and Upvote in case it helped or post your feedback to help !

    Regards