问题描述
我正在尝试登录计算机。
我一直在玩各种版本,并确定我过去的问题是当我不知道自己真正想做什么时。
I am trying to login into a computer.I have been playing with various versions and determined that my past questions were when I didn't know what I was really trying to do.
我发现运行脚本时,我在错误的PC上。
I discovered that I was on the incorrect PC when running the script.
现在在正确的PC上运行脚本时,以下代码要求我输入密码。
When I now run the script on the correct PC, the following code requires me to enter the password.
gwmi win32_service –credential domain\username –computer PC#
上面的当前脚本是否有办法在没有用户输入的情况下强制执行用户名和密码?我必须为100台PC执行此操作想遍历所有密码,而无需用户输入密码100次。
Is there a way with my current script above, to enforce the username and password without user entry? I have to do this for 100s of PCs so I want to loop through all of them without the user having to input the password 100s of times.
我尝试执行以下操作:
$Username = 'domain\username'
$Password = 'password'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$SecureString = $pass
# Users you password securly
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString –computer PC#
但是,出现错误找不到与参数名称 computer匹配的参数。
也尝试过:
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString
# Sets yous credentials to be used
#$RemoteConn = New-PSSession -ComputerName "PC#" -Credential $MySecureCreds -Authentication default
但RemoteConn无效
but the RemoteConn didn't work
推荐答案
WOW由于
所以我不知道我可以使用 $ MySecureCreds
作为凭证
So I didn't realize I can use the $MySecureCreds
as the -credential
答案:
$Username = 'domain\username'
$Password = 'password'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$SecureString = $pass
# Users you password securly
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString
gwmi win32_service –credential $MySecureCreds –computer PC#
这篇关于将密码传递到-credential的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!