Ok, so this may be an odd request but I am new to powershell but have been playing with it for a few days and had an idea but not to sure how to do it. I want to make a results table that will look something like the following.
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
I put together a command that seems to get the result I want but needs some tweaking to get the additional functionality that i require.
( Get-Content .\~temp.txt ) | Foreach-Object {$_ -replace "$Computername,.*", ($Computername + "," + $Attempts + "," + $Result + "," + $Time.ToShortTimeString() + "," + $Time.ToShortDateString())} | Set-Content .\~temp.txt
First things firsts. I need to load all the computers from the text file (Computers.txt) and load each one of them into the new file(~temp.txt) I was thinking something along the lines of the following.
(NOTE:Untested Yet, just an idea)
$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,"
}
Next is pulling the number of attempts from the line and the last result. I honestly can't find how to do this, hoping someone can show me how to do this with some comments that explain how they did it, or for some direction on what i should be googling. Thank you for taking the time to read this, any/all help is greatly appreciated.