使用PowerShell进行身份验证以终止进程

时间:2016-08-11 06:06:45

标签: powershell authentication terminate securestring

我希望能够从不同的工作站运行它,这意味着我们需要进行身份验证。我在下面有这个,但它似乎不起作用。你能看到什么错吗?

get-content .\killprocess.PS1

$username = 'je\leigh'
$password = cat 'U:\Accounts\Synergy Tools\securestring.txt' | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential `-argumentlist $username, $password

(Get-Content 'U:\Accounts\Synergy Tools\Computers.txt') | ForEach-Object {Get-WmiObject -computer $_ -class win32_process -filter "name='synergy.exe' or name='booking9.exe' or name='acl_apps.exe' or name='pos.exe' or name='booking.exe'" -credential $cred| %{$_.terminate()} | out-null}

1 个答案:

答案 0 :(得分:0)

如果<div id=messages tabindex=0>包含可读密码,例如securestring.txt。尝试使用MyP@ssWord!123&#39; ConvertTo-SecureString&amp; -AsPlainText参数:

-Force

这会将$password = Get-Content 'U:\...\securestring.txt' | ConvertTo-SecureString -AsPlainText -Force 中的文字转换为可读securestring.txt,可以SecureString查看:

$Password | ConvertFrom-SecureString

然后直接将01000000d08c9ddf0115d1118c7a00c04fc297eb010000000a65b1b20fe4e0418aece793d7242358 0000000002000000000003660000c00000001000000082e9a55adb7c90d9bed5946aed69e5380000 000004800000a000000010000000932bccf24879272d36536f6ef98e1be4180000006fb092d673a8 1f84b5954f9cb35daee2addb2d325ec25112140000005c8982b4cd15503000796213c3e0d3869780 变量直接发送到$password

如果您愿意,可以将-argumentlist $username, $password的输出存储到ConvertFrom-SecureString中,然后在脚本中使用以下内容:

securestring.txt

注意:如果$password = Get-Content 'U:\...\securestring.txt' | ConvertTo-SecureString 中有多行,则可能会出现错误,因为它会将securestring.txt变为一个字符串数组。