Advertisement
Guest User

Untitled

a guest
Nov 7th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. $user = "downloadusr"
  2. $pass = "Str0ngPassw0RD"
  3.  
  4. $scriptsurl = "http://foo.bar/scripts/"
  5.  
  6. $webclient = new-object System.Net.WebClient
  7. $credCache = new-object System.Net.CredentialCache
  8. $creds = new-object System.Net.NetworkCredential($user,$pass)
  9. $credCache.Add($scriptsurl, "Basic", $creds)
  10. $webclient.Credentials = $credCache
  11.  
  12. $scriptdir = "C:\scripts\"
  13. $scriptlist = $scriptsurl+"filelist.csv"
  14. $filelist = Import-Csv filelist.csv -Delimiter ";"
  15. $webclient.DownloadFile("$scriptlist","filelist.csv")
  16.  
  17.  
  18. if (!(test-path $scriptdir)){
  19. New-Item -ItemType "directory" -Path $scriptdir
  20. }
  21.  
  22.  
  23. foreach ($file in $filelist)
  24. {
  25. $scriptfile = $scriptdir+$file.filename
  26. if (!(Test-Path $scriptfile))
  27. {
  28. Write-Verbose "File $file.filename does not exist"
  29. $webclient.DownloadFile($scriptsurl+$file.filename,$scriptfile)
  30. }
  31. }
  32. else
  33. {
  34.  
  35. $remoteversion = $webclient.DownloadString($scriptsurl+$file.filename)[2]
  36. $localversion = (Get-Content $scriptfile)[1]
  37.  
  38. If ($localversion -ne $remoteversion)
  39. {
  40. write-Verbose "file $file.filename out of date"
  41. $webclient.DownloadFile($scriptsurl+$file.filename,$scriptfile)
  42. }
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement