An exception is generated if the download fails.
For details, see:
http://msdn.microsoft.com/en-us/library/ez801hhe(v=vs.110).aspx
$file1 = "URL"
$dir1 = "\\Share\Folder"
$file2 = "URL2"
$dir2 = "\\Share\Folder2"
$wc = New-Object System.Net.WebClient
[bool]$failed = $false
Try
{
$wc.DownloadFile( $file1, $dir1 )
}
Catch
{
$failed = $true
}
If( $failed )
{
Write-host "download failed"
}
Else
{
Write-host "download worked"
}
From: [email protected] [mailto:[email protected]] On
Behalf Of Orlebeck, Geoffrey
Sent: Friday, May 30, 2014 10:35 AM
To: [email protected]
Subject: [powershell] Logging Question
Hello Group
I'm pretty new to PowerShell, and while I have figured out logging in most
situations, I'm trying to log a web download success/failure when using
"New-Object System.Net.WebClient DownloadFile". Is this possible? I've been
able to get output files created, but they are always blank. Like I said, I'm
pretty new to PowerShell so just a little help would be greatly appreciated.
I'm attempting to download multiple files, but the gist of the script looks
like this:
---------------------------------
$file1 = "URL"
$dir1 = "\\Share\Folder<file:///\\Share\Folder>"
$file2 = "URL2"
$dir2 = "\\Share\Folder2<file:///\\Share\Folder2>"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($file1, $dir1)
$wc.DownloadFile($file2, $dir2)
--------------------------------
I wasn't sure if it has to do with using objects on the command (don't think
that makes a difference). I've tried out-file, start-transcript, verbose in
various attempts but each command has resulted in the same blank text file.
Just wondering if there is a better way. The goal is to get basic "file
downloaded success" and the path it downloaded to, just so we can confirm
if/when review is necessary. The script works to grab the files and place them
in the appropriate folders, just want log output so other people can see it,
too.
Thanks.
-Geoff
Confidentiality Notice: This is a transmission from Community Hospital of the
Monterey Peninsula. This message and any attached documents may be confidential
and contain information protected by state and federal medical privacy
statutes. They are intended only for the use of the addressee. If you are not
the intended recipient, any disclosure, copying, or distribution of this
information is strictly prohibited. If you received this transmission in error,
please accept our apologies and notify the sender. Thank you.
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1