-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovefiles1.ps1
More file actions
48 lines (34 loc) · 1.48 KB
/
movefiles1.ps1
File metadata and controls
48 lines (34 loc) · 1.48 KB
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
#Had to grant permissions first using the following:
#$w = Get-SPWebApplication -Identity https://***************
#$w.GrantAccessToProcessIdentity("domain\username")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
#Site Collection where you want to upload files
$siteCollUrl = "https://*******************************"
#Document Library where you want to upload files
$libraryName = "RotationGrids"
$spSourceWeb = Get-SPWeb $siteCollUrl;
$spSourceList = $spSourceWeb.Lists[$libraryName];
if($spSourceList -eq $null)
{
Write-Host "The Library $libraryName could not be found."
return;
}
$content = Get-Content D:\scripts\trustlist1.txt
foreach ($line in $content)
{
$reportFilesLocation = "D:\RotationGrids\" + $line
$files = ([System.IO.DirectoryInfo] (Get-Item $reportFilesLocation)).GetFiles()
foreach ($file in $files)
{
$fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()
$folder = $spSourceWeb.getfolder($libraryName)
$spFile = $folder.Files.Add($folder.Url + "/" + $line + "/" + $file.Name, [System.IO.Stream]$fileStream, $true)
#write-host $folder.Url"/"$line"/"$file
$fileStream.Close();
}
}
$spSourceWeb.dispose();
Write-Host "Files have been uploaded to" $libraryName