Hello all!
What I'm trying to accomplish is taking a txt file with computer numbers that are missing from our inventory.
computer1
computer2
computer3
computer4
The list of these computers, some are online, some are not. So the point of my application is to cycle through computers and when one is found do some items but it doesn't stop and continues to grind and once all of them have been found or the list is $null, do another action say send an email to our team so we can update our inventory. So far this is what I have but it doesn't seem to work. Note: I'm writing this with PowerShell Studio so DisplayInfo is just a text box and $OPENFILEDIALOG1.FILENAME is a browse button
$PCs=Get-Content$OPENFILEDIALOG1.FILENAME
$PCHash=@{}
ForEach($PCin$PCs)
{
$PCHash.Add($PC,$null)
}
Do
{
ForEach($PCin$PCHash.Keys)
{
If(Test-Connection $PC-Count1-Quiet)
{
$lastuser=Invoke-Command$PC-ScriptBlock {gci c:\users |?{$_.LastAccessTime }|sort LastWriteTime -desc |select-f1}
$ip=invoke-command$PC{ Ipconfig |Select-String IPv4 |Out-String}
$DisplayInfo.Lines +="$PC is owned by $lastuser"
$DisplayInfo.Lines +="IP is $($ip.Trim())"
$DisplayInfo.Lines +=""
$PCHash.Remove($PC)
}
}
}
Until($PCHash.Keys -eq$null)
{
$displayinfo.Lines +="All assets have been found"
}