powershellvirtual-machinepowershell-remoting

Can I connect a PSSession to a VM with no password?


I have a VM with no password that I want to connect to using PSSessions, but it fails if I try to provide an empty password:

> $s = New-PSSession -VMName "vm-240404"

cmdlet New-PSSession at command pipeline position 1
Supply values for the following parameters:
Credential
User: AdminUser
Password for user AdminUser:

New-PSSession: The credential is invalid.

I've tried building a PSCredential and a securestring manually and passing that in, but that also does not work:

> "" | ConvertTo-SecureString
ConvertTo-SecureString: Cannot bind argument to parameter 'String' because it is an empty string.

> $a = [securestring]::new()
> $c = [pscredential]::new("AdminUser", $a)
> $s = New-PSSession -VMName "vm-240404" -Credential $c
New-PSSession: The credential is invalid.

Can this be done, or do VMs need passwords to be compatible with PSSessions? The docs about PowerShell Direct on VMs don't say anything explicitly about this.


Solution

  • I believe there is simply an undocumented, implicit requirement that to support PSRemoting, VMs must have an admin password.

    This is borne out because securestrings are invalid when empty (again, no documentation I could find), and therefore PSCredentials are invalid with empty passwords (ditto), and therefore New-PSSession will fail with no password.