michalek19
asked on
BAK audit script
Hi
I am having problem to run this script against multiple servers and selected drives.
For some reason this script checks bak files only for one drive and one server.
Also i would like to be able to send an email with attachement.
Can you please help me to resolve this matter?
$ComputersPath = "e:\utils\computers.txt"
$LogPath = "e:\utils"
$Log = @()
ForEach ($Computer in (Get-Content $ComputersPath))
{ If ($Computer)
{ ForEach ($Drive in "E","F","I","G")
{ If (Test-Path "\\$Computer\$($Drive)`$\" -ErrorAction Stop)
{ $Log += ForEach ($BAK in ($BAKS = Get-ChildItem "\\$Computer\$($Drive)`$\" -Include *.bak -Recurse -Force -erroraction SilentlyContinue))
{ New-Object PSObject -Property @{
ComputerName = $Computer
Path = $BAK.DirectoryName
FileName = $BAK.BaseName
Size = "{0:N2} MB" -f ($BAK.Length / 1mb)
}
}
}
}
}
}
$Log | Export-Csv $LogPath\BAKAUDITLog.csv -NoTypeInformation
I am having problem to run this script against multiple servers and selected drives.
For some reason this script checks bak files only for one drive and one server.
Also i would like to be able to send an email with attachement.
Can you please help me to resolve this matter?
$ComputersPath = "e:\utils\computers.txt"
$LogPath = "e:\utils"
$Log = @()
ForEach ($Computer in (Get-Content $ComputersPath))
{ If ($Computer)
{ ForEach ($Drive in "E","F","I","G")
{ If (Test-Path "\\$Computer\$($Drive)`$\"
{ $Log += ForEach ($BAK in ($BAKS = Get-ChildItem "\\$Computer\$($Drive)`$\"
{ New-Object PSObject -Property @{
ComputerName = $Computer
Path = $BAK.DirectoryName
FileName = $BAK.BaseName
Size = "{0:N2} MB" -f ($BAK.Length / 1mb)
}
}
}
}
}
}
$Log | Export-Csv $LogPath\BAKAUDITLog.csv -NoTypeInformation
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.