On Feb 25, 9:54*pm, drew <d...@xxxxxx> wrote:
> for a particular missing Access file, the location of which i know not, and
> has been lost to species memory. i know we have active directory somewhere
> too, but not how to query it for the list of computers, but assuming i can
> get a list of computers from net view and send it to compters.txt, how doi
> get to be able to do something like
>
> foreach ($computer in $computers) {
> get-childitem \\$computer\c:\MyMissing.MDB recurse>>\\myHostMachine.Found..txt}
>
> i mean, that's what i want, but something(s) missing...
> isn't there a way to redirect the error flow to null so that i dont get
> those pesky Access Denied nags that seem to ignore the silently continue?*
> 2>null? where does it go?
>
> Still, it would be nice to be able to log the denying maching name too,
> since the MDB must be found, by ethernet or sneaker net.
> thanks very much gang OK, if this is a joke, I don't get it. The Header does not match the
question.
Anyway, Here is a POSH script that will do what you ask for in the
body of your post.
You need Excel on the machine you run this script on.
The output goes to C:\temp\find_MDB.xls
#<--- Start Script --------->
$a = get-date -format g
$row = 2
$xl = New-Object -c excel.application
$xl.visible = $True
$wb = $xl.workbooks.add()
$sh = $wb.sheets.item(1)
$sh.Range("A1:T1").Font.Bold = $true
$sh.Range("A:A").Font.Bold = $True
$sh.Cells.Item(1, 1) = "Computer Name"
$sh.Cells.Item(1, 2) = "Date Run " + $a
$computerlist = Get-Content 'c:\compters.txt'
foreach ($srv in $computerlist)
{
$sh.Cells.Item($row, 1) = $srv
# This is all one line -->
$response = Get-WmiObject -query "Select * From Win32_PingStatus Where
Address = '$srv'"
# <---
if( ($response -eq $null) -or ($response.StatusCode -ne 0)) {
$sh.Cells.Item($row, 2).Font.ColorIndex = 3
$sh.Cells.Item($row, 2) = "Does Not Ping"
$row++
} else { if ($response.TimeToLive -le 64)
{
$sh.Cells.Item($row, 2).Font.ColorIndex = 5
$sh.Cells.Item($row, 2) = "probably is a Unix host"
$row++
} Else {
# This is all one line -->
$Var3 = Get-ChildItem -path \\$srv\c$ -recurse -Filter "MyMissing.MDB"
-ea continue
# <---
if ($Var3) {
foreach ($objItem in $Var3) {
$sh.Cells.Item($row, 3) = $objItem.FullName
$row++ }
} Else {
$sh.Cells.Item($row, 2).Font.ColorIndex = 3
$sh.Cells.Item($row, 2) = $error[0].tostring() }
$row++
}
} $sh.Cells.EntireColumn.AutoFit()
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
$wb.SaveAs("C:\temp\find_MDB.xls")
# close and release resources
$wb.close($false)
$xl.quit()
spps -n excel
#<------ End Script -------->