-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransferFSLogixProfiles.ps1
More file actions
68 lines (56 loc) · 2.56 KB
/
transferFSLogixProfiles.ps1
File metadata and controls
68 lines (56 loc) · 2.56 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# This script transfers users fslogix profiles from one Azure Fileshare to another.
#Author: David Cox
#Date: 11/11/2024
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All"
# Read the usernames from the file
$users = Get-Content -Path "C:\temp\users.txt"
# Prompt for SAS tokens
$sbtprofiles1SASToken = Read-Host -Prompt "Enter the SAS Token for sbtprofiles1"
$sbtprofiles2SASToken = Read-Host -Prompt "Enter the SAS Token for sbtprofiles2"
$ncususerprofSASToken = Read-Host -Prompt "Enter the SAS Token for ncususerprof"
$cususerprofSASToken = Read-Host -Prompt "Enter the SAS Token for cususerprof"
# For each user
foreach ($user in $users)
{
# Construct the userPrincipalName
$userPrincipalName = "$user@sterlingbank.com"
# Get user info from Microsoft Graph
try
{
$userObject = Get-MgUser -UserId $userPrincipalName -Property "id,onPremisesSamAccountName,userPrincipalName"
}
catch
{
Write-Host "User not found: $userPrincipalName"
continue
}
# Extract username
$username = $userObject.OnPremisesSamAccountName
if (-not $username)
{
$username = $userObject.MailNickname
}
if (-not $username)
{
$username = $userObject.UserPrincipalName.Split('@')[0]
}
if (-not $username)
{
Write-Host "Username not found for user $userPrincipalName"
continue
}
# Build the source and destination URLs without wildcard in the path
$source1 = "https://sbtprofiles1.file.core.windows.net/user-prof1-centus-prod?$($sbtprofiles1SASToken)"
$destination1 = "https://ncususerprof.file.core.windows.net/north-central-us-fslogix-fileshare?$($ncususerprofSASToken)"
$source2 = "https://sbtprofiles2.file.core.windows.net/user-prof1-centus-prod?$($sbtprofiles2SASToken)"
$destination2 = "https://cususerprof.file.core.windows.net/central-us-fslogix-fileshare?$($cususerprofSASToken)"
# Define the regex pattern to include directories starting with the username
$regexPattern = "^$username.*"
# Output the commands for debugging
Write-Host "Copying from $source1 to $destination1 with regex '$regexPattern'"
Write-Host "Copying from $source2 to $destination2 with regex '$regexPattern'"
# Run the azcopy commands using --include-regex
azcopy copy "$source1" "$destination1" --recursive --preserve-permissions=true --preserve-smb-info=true --include-regex "$regexPattern" --dry-run
azcopy copy "$source2" "$destination2" --recursive --preserve-permissions=true --preserve-smb-info=true --include-regex "$regexPattern" --dry-run
}