0

On Debian 11, I have installed PowerShell 7.3.0. I am testing if I can run commands on a remote Windows computer. This is a simple example to get the remote computer hostname.

#!/usr/bin/env pwsh

$username = "Administrator"
$password = "passgoeshere"
$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $user, $secureStringPwd

Invoke-Command -ComputerName 192.168.xxx.xxx -Credential $cred -ScriptBlock { hostname }

My problem is that when I run this script, I still get a prompt to enter a username and password.

PowerShell credential request
Enter your credentials.
User:

It's not a problem with the credentials because when I enter them manually, it gives me the hostname of the remote computer.

I think it has something to do with the way PowerShell on Linux reads the credentials.

What can I do to get the script not to prompt for user/pass?

edit: the issue was a typo

4
  • I don't suppose it's a simple typo of $user for $username? Nov 22, 2022 at 21:02
  • yes, I found that out later on. just a typo.
    – aristosv
    Nov 24, 2022 at 6:57
  • Is it still a problem and it's a typo to fix in the question, or the problem went away after changing the variable? Nov 24, 2022 at 12:42
  • Please don't edit the solution into your question, that way the question stays as unsolved in the system forever. Instead, post your solution as an answer and accept it. Even when it just was a typo. Or ask the user who provided the solution to post it as an answer, so you can accept it. Nov 25, 2022 at 13:07

2 Answers 2

0

there was a typo in the script

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Dec 7, 2022 at 16:45
0

Your script it's ok. Change variable $username to $user

I used "Invoke-VMSscript"

$user = "root"

$password = "P@ssword"

$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force

$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $user, $secureStringPwd

Invoke-VMScript -VM My_VM -ScriptText "hostname" -GuestCredential $cred -ScriptType Bash

ScriptOutput
-----------------------------------------------------------------------------------------------------------------------|  My_VM
|  
-----------------------------------------------------------------------------------------------------------------------

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .