This is a script I wrote to run smartctl.exe remotely using psexec.
I added a few parameters, which can be changed or not used entirely. This was written quickly but works well if you have administrator access to the remote PC.
You do need my Search-Computer function to use it as is, which assumes you're using AD :)
function Search-Computer {
param(
$srcComputer = $(Throw "Please specify a computer name.")
)
$srcComputer = "*" + $srcComputer + "*"
$cmpList = Get-QADComputer -Name $srcComputer -ip LastLogonTimeStamp
if ($cmpList.count -gt 1) {
$i = 0
Write-Host "----------------------------------" -fore Gray
Write-Host "Computer listing for $srcComputer" -fore Red
Write-Host "----------------------------------" -fore Gray
ForEach ($cmp in $cmpList) {
$cmpName = $cmp.Name
$cmpEnabled = $cmp.AccountIsDisabled
$cmpDN = $cmp.DN
$cmpLastllt = $cmp.LastLogonTimeStamp
if ($cmpEnabled -eq $true) {
$cmpEnabled = "This computer is disabled!"
} else {
$cmpEnabled = ""
}
Write-Host "------------------------" -fore gray
Write-Host "[$i] Name : " $cmpName
Write-Host "Last Logon : " $cmpLastllt
Write-Host "OU :" $cmpDN
Write-Host $cmpEnabled -fore red
Write-Host "------------------------" -fore gray
$i++
}
Write-Host "----------------------------------" -fore Gray
$cmpSelection = Read-Host "Please [select] a number"
Return ($cmpList[$cmpSelection]).Name
} else {
if ($cmpList) {
Return $cmpList.Name
} else {
Return Write-Error "$srcComputer not found in AD."
}
}
}
No comments yet. Be the first!