Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. $SharePoint = "https://Share.MyCompany.com/MyCustomer/WorkLoad.docx"
  2. $Path = "$ScriptPath$($CustomerName)_WorkLoad.docx"
  3.  
  4. #Get User Information
  5. $user = Read-Host "Enter your username"
  6. $username = "$user@MyCompany"
  7. $password = Read-Host "Enter your password" -AsSecureString
  8.  
  9. #Download Files
  10. $WebClient = New-Object System.Net.WebClient
  11. $WebClient.Credentials = New-Object System.Net.Networkcredential($UserName, $Password)
  12. $WebClient.DownloadFile($SharePoint, $Path)
  13.  
  14. $SharePoint = Read-Host 'Enter the full path to Delivery Site'
  15. $LocalDrive = 'P:'
  16. $Credentials = Get-Credential
  17.  
  18.  
  19. if (!(Test-Path $LocalDrive -PathType Container)) {
  20. $retrycount = 0; $completed = $false
  21. while (-not $completed) {
  22. Try {
  23. if (!(Test-Path $LocalDrive -PathType Container)) {
  24. (New-Object -ComObject WScript.Network).MapNetworkDrive($LocalDrive,$SharePoint,$false,$($Credentials.username),$($Credentials.GetNetworkCredential().password))
  25. }
  26. $Completed = $true
  27. }
  28. Catch {
  29. if ($retrycount -ge '5') {
  30. Write-Verbose "Mapping SharePoint drive failed the maximum number of times"
  31. throw "SharePoint drive mapping failed for '$($SharePoint)': $($Global:Error[0].Exception.Message)"
  32. } else {
  33. Write-Verbose "Mapping SharePoint drive failed, retrying in 5 seconds."
  34. Start-Sleep '5'
  35. $retrycount++
  36. }
  37. }
  38. }
  39. }
  40.  
  41. #Get User Information
  42. $user = Read-Host "Enter your username"
  43. $username = "$user@MyCompany"
  44. $password = Read-Host "Enter your password" -AsSecureString
  45.  
  46. #Gathering the location of the Card Formats and Destination folder
  47. $Customer = "$SharePointMyCustomer"
  48. $Products = "$Path$($CustomerName)Products"
  49.  
  50. #Get Documents from SharePoint
  51. $credential = New-Object System.Management.Automation.PSCredential($UserName, $Password)
  52. New-PSDrive -Credential $credential -Name "A" -PSProvider "FileSystem" -Root "$SharePoint"
  53. net use $spPath #$password /USER:$user@corporate
  54.  
  55. #Get PMDeliverables file objects recursively
  56. Get-ChildItem -Path "$Customer" | Where-Object { $_.name -like 'MS*' } | Copy-Item -Destination $Products -Force -Verbose
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement