-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileTransfer.ps1
116 lines (83 loc) · 3.52 KB
/
FileTransfer.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#Import-Module Az.Storage
$scsv = 'source csv path'
$outfile = "output csv path"
$sourceStorageAccountName ="XXXXX"
$sourceStorageAccountKey = "XXXXX"
$sContainer = "sourceContainer"
$context = New-AzStorageContext -StorageAccountName $sourceStorageAccountName -StorageAccountKey $sourceStorageAccountKey
$desStorageAccountName ="XXXXX"
$desStorageAccountKey = "XXXXX"
$desContainer = "destinationContainer"
$desContext = New-AzStorageContext -StorageAccountName $desStorageAccountName -StorageAccountKey $desStorageAccountKey
$start = 0
$batchsize = 500
$end = $batchsize
$processrows = Import-Csv -Path $outfile -Delimiter '|'
if($processrows.count -gt 0)
{
$start = [int]$processrows[$processrows.count -1].sn
}
else
{
$start = 0
}
$end = $start + $batchsize
$rows = Import-Csv -Path $scsv -Delimiter '|'
$processrows = [System.Collections.ArrayList]@()
for($i=$start; $i -le $end -and $i -le $rows.Count-1 ; $i++)
{
$item = $rows[$i]
$blob = $item.downloadlink
if($item.filetype -ne "pdf" -and $item.filetype -ne "doc" -and $item.filetype -ne "docx" -and $item.filetype -ne "pptx" -and $item.filetype -ne "ppt" -and $item.filetype -ne "txt")
{
try
{
$dblobpath = 'transferred-files/'+$item.downloadlink
$srcBlob = Get-AzStorageBlob -Container $sContainer -Blob $blob -Context $context -ErrorAction Stop
$destBlob = $srcBlob | Copy-AzStorageBlob -DestContainer $desContainer -DestBlob $dblobpath -DestContext $desContext -Force -ErrorAction Stop
#copy-AzStorageBlob -SrcBlob $srcBlob -SrcContainer $sContainer -DestContainer $desContainer -DestBlob $dblobpath -Context $context -DestContext $desContext -Force -ErrorAction Stop
$hash = @{
"sn" = $item.sn
"filename" = $item.filename
"filetype" = $item.filetype
"downloadlink" = $blob
"status" = "success"
"at" = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"size" = $item.metadata_storage_size
"error" =""
}
$newRow = New-Object PsObject -Property $hash
$processrows.Add($newRow)
}
catch {
$hash = @{
"sn" = $item.sn
"filename" = $item.filename
"filetype" = $item.filetype
"downloadlink" = $blob
"status" = "failed"
"at" = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"size" = $item.metadata_storage_size
"error" = $_.Exception.Message
}
$newRow = New-Object PsObject -Property $hash
$processrows.Add($newRow)
}
}
else
{
$hash = @{
"sn" = $item.sn
"filename" = $item.filename
"filetype" = $item.filetype
"downloadlink" = $blob
"status" = "skip"
"at" = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"size" = $item.metadata_storage_size
"error" = $item.filetype
}
$newRow = New-Object PsObject -Property $hash
$processrows.Add($newRow)
}
}
$processrows |Export-Csv $outfile -Append -Delimiter '|' -Force -NoTypeInformation