Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $user = "downloadusr"
- $pass = "Str0ngPassw0RD"
- $scriptsurl = "http://foo.bar/scripts/"
- $webclient = new-object System.Net.WebClient
- $credCache = new-object System.Net.CredentialCache
- $creds = new-object System.Net.NetworkCredential($user,$pass)
- $credCache.Add($scriptsurl, "Basic", $creds)
- $webclient.Credentials = $credCache
- $scriptdir = "C:\scripts\"
- $scriptlist = $scriptsurl+"filelist.csv"
- $filelist = Import-Csv filelist.csv -Delimiter ";"
- $webclient.DownloadFile("$scriptlist","filelist.csv")
- if (!(test-path $scriptdir)){
- New-Item -ItemType "directory" -Path $scriptdir
- }
- foreach ($file in $filelist)
- {
- $scriptfile = $scriptdir+$file.filename
- if (!(Test-Path $scriptfile))
- {
- Write-Verbose "File $file.filename does not exist"
- $webclient.DownloadFile($scriptsurl+$file.filename,$scriptfile)
- }
- }
- else
- {
- $remoteversion = $webclient.DownloadString($scriptsurl+$file.filename)[2]
- $localversion = (Get-Content $scriptfile)[1]
- If ($localversion -ne $remoteversion)
- {
- write-Verbose "file $file.filename out of date"
- $webclient.DownloadFile($scriptsurl+$file.filename,$scriptfile)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement