我请求您提供帮助,以检查Windows本地用户帐户和 密码工作正常与否。
问题详细信息:当用户名名称模式喜欢使用本地用户帐户“。\ administrator”登录时,我无法读取/使用。在选项1中,凭据仅适用于username @ domain或domain \ user。在选项2中,我无法读取“。\ administrator”。
注意:我的脚本在使用用户名模式(例如“管理员”或“本地\管理员”)时可以正常工作。像“。\ administrator”这样的输入时,只有它不起作用。
下面是我使用的代码。
选项1 :(附加屏幕截图)
Write-Host 'Enter your crdentials with username and password'
$Credentials = Get-Credential
try
{
Invoke-VMScript -VM jumpbox1 -ScriptType Powershell -ScriptText "(gwmi Win32_NetworkAdapter -filter 'netconnectionid is not null').netconnectionid" -GuestCredential $Credentials -ErrorAction stop | out-null
Write-Host 'Crdential works'
}
catch
{
Write-Host 'Invalid Crdential works'
}
选项2:
$Username = Read-Host -Prompt 'Enter the username: '
$GuestPasswd = Read-Host -Prompt 'Enter the Password: ' -AsSecureString
$Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($GuestPasswd))
try
{
Invoke-VMScript -VM jumpbox1 -ScriptType Powershell -ScriptText "(gwmi Win32_NetworkAdapter -filter 'netconnectionid is not null').netconnectionid" -GuestCredential $Credentials -ErrorAction stop | out-null
Write-Host 'Crdential works'
}
catch
{
Write-Host 'Invalid Crdential works'
}
错误:-cred02.ps1
输入用户名::。\ administrator
Invoke-VMScript:2019/6/12 1:50:03 Invoke-VMScript指定的参数不是
正确:
在cred02.ps1:36 char:1
+ Invoke-VMScript -VM jumpbox1 -ScriptType Powershell -ScriptText“(gwmi Win3 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo:未指定:(:) [Invoke-VMScript],InvalidArgument
+ FullyQualifiedErrorId:Client20_VmGuestServiceImpl_RunScriptInGuest_ViError,VMware.VimA
utomation.ViCore.Cmdlets.Commands.InvokeVmScript
输入用户名::“。\ administrator”
Invoke-VMScript:2019/6/12 1:51:44 Invoke-VMScript无法通过身份验证
使用提供的凭据的来宾操作系统。
在cred02.ps1:36 char:1
+ Invoke-VMScript -VM jumpbox1 -ScriptType Powershell -ScriptText“(gwmi Win3 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo:未指定:(:) [Invoke-VMScript],InvalidGuestLogin
+ FullyQualifiedErrorId:Client20_VmGuestServiceImpl_RunScriptInGuest_ViError,VMware.VimA
utomation.ViCore.Cmdlets.Commands.InvokeVmScript