| I'm new to Powershell and trying to use HTTRack to produce a folder with a
scrape of various sites on a monthly basis.
I can get the POWERSHELL to invoke HTTrack, but HTTrack returns a File Not
Found. I cannot figure out my issue.
clear-host
write-output "---------------------Script Start--------------------";
write-output " HTTrack Site Backup Powershell Script"
write-output "-------------------------------------------------------";
# get timestamp
$timestamp = Get-Date -format yyyy_MMM_dd_HHmmss
write-output "The current time is $timestamp."
# invoke HTTrack
$HTTrackPath="C:\WinHTTrack\WinHTTrack.exe"
write-output "This PowerShell script is invoking HTTrack at $HTTrackPath."
# creates output directory if it doesn't already exist
$local = Get-Location;
$TargetFolderPath = "C:\PowershellTest\test-$timestamp"
if(!$local.Equals("C:\"))
{
cd "C:\";
if((Test-Path $TargetFolderPath) -eq 0)
{
mkdir $TargetFolderPath;
cd $TargetFolderPath;
write-output "Created Output directory at $TargetFolderPath."
}
}
# end create directory
# set error action preference so errors don't stop and the trycatch
# set website source
$sourceSite = <http://www.doc.state.mn.us>
# Specify EventLog Source
if ([System.Diagnostics.EventLog]::SourceExists("WinHTTrackScript") -eq
$False) {
New-EventLog -LogName "Network" -Source "WinHTTrackScript"
}
#End Specify EventLog Source
# Test that file was created accurately by copying a file from another folder.
This has NOTHING to do with HTTrack- Just a test to make sure path is correct
$copyItem ="c:\WinHTTrack\unrestricted.txt"
Copy-Item $copyItem $TargetFolderPath
write-output "Test file copied $copyItem to $TargetFolderPath"
# End Test file creation- This has NOTHING to do with HTTrack- Just a test to
make sure path is correct
try
{
write-output "Downloading data ..."
invoke-expression "$HTTrackPath $sourceSite -O $TargetFolderPath"
write-eventlog -LogName "Network" -Source "WinHTTrackScript" -EventId 1
-Message "Downloaded site for backup"
}
catch
{
# error occurred so lets report it
write-output "ERROR OCCURRED DURING SCRIPT " $error
# write an event to the event log
write-output "Writing FAIL to EventLog"
write-eventlog -LogName "Network" -Source "WinHTTrack" -EventId 1 -Message
"Download for backup FAILED during execution. $error" -EntryType Error
}
| |