Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I need to pass a User name and

Status
Not open for further replies.

Tester_V

Technical User
Nov 22, 2019
54
US
Hi,
I need to pass a User name and a Pass to the PS script.
I tried to find it online but could not.
Ant idea how to do this?

Code:
Invoke-Command -Computer DESK-2.domain.somecorp.com -Scriptblock {C:\Python39\python.exe 'C:\temp\DT_Col\HN.py'}

thank you.
 
Hi, thank you for helping me with this!
I need to accomplish two things.
1. get the Process list from a remote computer
2. start a script on a remote host

I tested both one-liners, I ran it from my laptop to get the Process list and to execute a Python script on my desktop.
Of course, both PCs have the same user accounts and ran without any problems.
What I need is to execute both scripts from my server on a bunch of remote hosts and the hosts do not have my account in the Admin group.
But I have a user name/password to log in to the Hosts,
I just need to add '$credentials' to the script. I do not know how to do that.
Here are the one-liners I have:
Code:
Invoke-Command -ComputerName someone-desk2 -ScriptBlock {Get-Process}

Second one-liner:
Code:
Invoke-Command -Computer someone-DESK2 -Scriptblock {python.exe 'C:\Python_Test\Remote_Access\rem-Exec-01.py'}

Thank you!
 
Have you checked that the remote devices have PowerShell Remoting enabled, i.e. WinRM and Remote Registry enabled/running, including their firewalls accepting remote PS commands?
 
Yes, 'PowerShell Remoting enabled' - is enabled.

Thank you.
 
Are you in a domain or workgroup environment? If it's domain then I cannot help... no experience.

If it's a workgroup then I assume you're using basic authentication?

What response do you get when you enter:

Code:
Test-WsMan someone-desk2

I'm in a workgroup environment and can test the PSRemoting connection by either IP address or computername. So, for example, I enter:

Code:
test-wsman DESKTOP-MSV1KLP

... and see this:

psremoting_test_connection_nw5eex.png


This shows a successful connection. You should see similar.

Next, I invoke:

Code:
Invoke-Command -ComputerName DESKTOP-MSV1KLP -ScriptBlock {Get-Process} -credential user

(where 'user' is the account I'm going to use) and the credential request dialog appears for me to authenticate:

psremoting_credential_request_bkb3np.png


That's how you authenticate in a workgroup environment - using the -credential parameter to invoke the challenge/response. Are you seeing similar?

Note that this is only a temporary session and will close after the command or scriptblock ends.

If I wanted to run several cmdlets then I would use:

Code:
Enter-PSSession -ComputerName DESKTOP-MSV1KLP -Credential user

Once the session is established, your prompt will change to show the remote computer you’re connected to and you should then be able to execute any number of cmdlets directly without you having to continually add the Invoke-Command cmdlet and the remote computername.

Hope this helps...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top