Is this possible? It should also be able to take the credentials. Something similar to what psexec does. ps1 script is already stored in the remote system.
Ex Client1 is having C:\Temp\test.ps1 and I should be able to launch it from Server1's powershell console using a supplied credentials and Psremoting is not enabled in Client1.
You could potentially use the Win32-Process WMI class, but keep in mind that the "designed" solution for this is Remoting. PowerShell doesn't natively provide an alternative, although as I mentioned you could possibly use WMI.
The thought of doing this through WMI intrigued me so I started some experiments. You can get WMI/CIM to start a new powershell session and run a script
$computer = $env:COMPUTERNAME
The major draw back to using this approach is getting the data back.
You are creating a new PowerShell process and your script will run in the context of that process. PowerShell doesn't allow for data being moved across instances. You could get you script to write output to a location you can access but that is starting to build in a lot of complications to avoid using remoting
I did think of trying to use a CIM session but you still run into the issue of opening a separate PowerShell session from which you can't return the data
Remoting is designed specifically for this scenario and is the recommended way to approach this type of problem
You must be logged in to reply to this topic.