Linux에서 PowerShell을 사용하여 인증 프로세스를 자동화할 수 없습니다.

Linux에서 PowerShell을 사용하여 인증 프로세스를 자동화할 수 없습니다.

Debian 11에는 PowerShell 7.3.0을 설치했습니다. 원격 Windows 컴퓨터에서 명령을 실행할 수 있는지 테스트 중입니다. 이것은 원격 컴퓨터 호스트 이름을 얻는 간단한 예입니다.

#!/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 }

내 문제는 이 스크립트를 실행할 때 사용자 이름과 비밀번호를 입력하라는 메시지가 계속 표시된다는 것입니다.

PowerShell credential request
Enter your credentials.
User:

자격 증명을 수동으로 입력하면 원격 컴퓨터의 호스트 이름이 표시되므로 자격 증명에는 문제가 없습니다.

Linux의 PowerShell이 ​​자격 증명을 읽는 방식과 관련이 있다고 생각합니다.

사용자/패스에 대한 메시지를 표시하지 않도록 스크립트를 얻으려면 어떻게 해야 합니까?

편집 : 문제는 오타였습니다

답변1

스크립트에 오타가 있었습니다

답변2

귀하의 스크립트는 괜찮습니다. $username 변수를 $user로 변경합니다.

"Invoke-VMSscript"를 사용했습니다.

$user = "루트"

$password = "P@ssword"

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

$cred = 새 개체 System.Management.Automation.PSCredential -ArgumentList $user, $secureStringPwd

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

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

관련 정보