[英]Authenticating with PowerShell to Kill Process
我希望能夠從不同的工作站運行它,這意味着我們需要進行身份驗證。 我在下面有這個,但它似乎不起作用。 你能看到什么錯嗎?
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}
如果securestring.txt
包含可讀密碼,例如MyP@ssWord!123
。 嘗試使用ConvertTo-SecureString
的-AsPlainText
和-Force
參數:
$password = Get-Content 'U:\...\securestring.txt' | ConvertTo-SecureString -AsPlainText -Force
這會將securestring.txt
的文本轉換為可讀的SecureString
,可以使用$Password | ConvertFrom-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
中有多行,則可能會出錯,因為它會將$password
變為一個字符串數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.