0
好的,所以這可能是一個奇怪的要求,但我是新來的PowerShell,但一直在玩它幾天,並有一個想法,但不知道該怎麼做。我想創建一個如下所示的結果表。Powershell Building日誌表
Computer Name(s) Attempt(s) Result Last Attempt
Computer1 1 Successful 9:31 25 Oct 12
Computer2 24 Unsuccessful 12:08 25 Oct 12
Computer3 9 Successful 11:22 25 Oct 12
Computer4 11 Unsuccessful 04:11 25 Oct 12
Computer5 12 Unsuccessful 07:19 25 Oct 12
我放在一起似乎得到我想要的結果,但需要一些調整,以獲得我需要的額外功能的命令。
(Get-Content .\~temp.txt) | Foreach-Object {$_ -replace "$Computername,.*", ($Computername + "," + $Attempts + "," + $Result + "," + $Time.ToShortTimeString() + "," + $Time.ToShortDateString())} | Set-Content .\~temp.txt
第一件事第一。我需要從文本文件(Computers.txt)中加載所有計算機,並將它們中的每一個加載到新文件中(〜temp.txt)。我正在考慮以下內容。
(注:未經檢驗然而,只是一個想法)
$Computers = Get-Content .\computers.txt
IF (Test-Path .\~temp.txt) {
IF (Select-String .\~temp.txt -pattern $Computer -quiet) {} ELSE { Add-Content ./~test.txt "$Computer," }
} ELSE {
ForEach ($Computer in $Computers) {
add-content .\~temp.txt "$Computer,"
}
接下來是拉動從行和最後結果的嘗試次數。我真的無法找到如何做到這一點,希望有人能告訴我如何做到這一點,並解釋他們是如何做到這一點的,或者對於我應該使用Google進行搜索的某些方向。感謝您花時間閱讀本文,非常感謝任何/所有幫助。