-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-repos-script-windows.ps1
More file actions
64 lines (53 loc) · 2.06 KB
/
Copy pathupdate-repos-script-windows.ps1
File metadata and controls
64 lines (53 loc) · 2.06 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
# Specify the file containing the profiles
$file = "C:\Users\test\.aws\config"
# Get all lines from the file
$lines = Get-Content -Path $file
# Initialize list to store profile names
$profiles = @()
# Loop over all lines
foreach ($line in $lines) {
# Check if it's a profile line
if ($line -match '\[profile (.*)\]') {
$profiles += $Matches[1]
}
}
# Print all profile names
Write-Output "Profiles found:"
$profiles
# Ask the user if they want to update the SSO profile
$updateSsoProfile = Read-Host -Prompt "Do you want to update the SSO profile? (yes/no)"
if ($updateSsoProfile -eq "yes") {
# Ask the user for which profile they want to login to AWS SSO
$selectedProfile = Read-Host -Prompt "Enter the profile you want to login to AWS SSO with (leave empty to update all profiles)"
if ($selectedProfile) {
if ($profiles -contains $selectedProfile) {
# Run aws sso login command for the selected profile
Write-Output "Logging in to AWS SSO with profile $selectedProfile"
Start-Process -Wait -NoNewWindow -FilePath "aws" -ArgumentList "sso login --profile $selectedProfile"
} else {
Write-Output "Profile $selectedProfile not found"
}
} else {
# Run aws sso login command for all profiles
$profiles | ForEach-Object {
Write-Output "Logging in to AWS SSO with profile $_"
Start-Process -Wait -NoNewWindow -FilePath "aws" -ArgumentList "sso login --profile $_"
}
}
}
# Specify the directory containing the repos
$dir = "C:\Users\test\REPO"
# Get all subdirectories
$directories = Get-ChildItem -Path $dir -Directory
# Loop over all subdirectories in parallel
$directories | ForEach-Object -Parallel {
# Change to the directory
Set-Location -Path $_.FullName
# Check if it's a git repository
if (Test-Path .git) {
Write-Output "Updating $($_.FullName)"
# Checkout main branch and pull
git checkout main
git pull
}
}