The following code is wrong
-----
$pathsToScan = @("C:\Users", "C:\ProgramData", "C:\Scripts")
$logPath = "C:\VBSScriptScan\VbsFiles_$(hostname).csv"
$results = foreach ($path in $pathsToScan) {
if (Test-Path $path) {
Get-ChildItem -Path $path -Filter *.vbs -Recurse -ErrorAction SilentlyContinue |
Select-Object FullName, LastWriteTime, Length
}
}
$pathsToScan = @("C:\Users", "C:\ProgramData", "C:\Scripts")
$logPath = "C:\VBSScriptScan\VbsFiles_$(hostname).csv"
$results = foreach ($path in $pathsToScan) {
if (Test-Path $path) {
Get-ChildItem -Path $path -Filter *.vbs -Recurse -ErrorAction SilentlyContinue |
Select-Object FullName, LastWriteTime, Length
}
}
Shouldn't the code be something like
---
$pathsToScan = @("C:\Users", "C:\ProgramData", "C:\Scripts")
$logPath = "C:\VBSScriptScan\VbsFiles_$(hostname).csv"
$results = foreach ($path in $pathsToScan) {
if (Test-Path $path) {
Get-ChildItem -Path $path -Filter *.vbs -Recurse -ErrorAction SilentlyContinue |
Select-Object FullName, LastWriteTime, Length
}
}
$results | Export-CSV -PATH $logPath