Skip to content

Commit 432dda8

Browse files
authored
Enhance kickoff script with Azure CLI setup
Added installation of Azure Automation CLI extension and configuration for dynamic installation of missing CLI extensions.
1 parent 2695c99 commit 432dda8

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

generic/kickoff.ps1

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Set-Location "C:\Users\mcontestabile\foo"
1+
Set-Location "C:\Users\mcontestabile\OneDrive - American Iron and Metal\Desktop"
22

33
# Determine PSVersion once
44
$pv = $PSVersionTable.PSVersion
@@ -9,7 +9,7 @@ Function Start-MyCommands {
99

1010
Write-Host "⚡Executing startup tasks..." -ForegroundColor Green
1111
#Ensure PSGallery exists and is trusted
12-
if (-not(Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) {
12+
if (-not(Get-PSRepository -Name PSGallery -ErrorAction Continue)) {
1313
Register-PSRepository -Name PSGallery -SourceLocation 'https://www.powershellgallery.com/api/v2' -InstallationPolicy Trusted
1414
} else {
1515
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
@@ -19,13 +19,13 @@ Function Start-MyCommands {
1919

2020
#Update PowerShellGet / PackageManagement to avoid missing parameter issues
2121
try {
22-
Install-Module -Name PowerShellGet -Force -Scope CurrentUser -ErrorAction Stop
22+
Install-Module -Name PowerShellGet -Force -Scope CurrentUser -ErrorAction Continue
2323
} catch {
2424
#Write-Verbose "⚡PowerShellGet update skipped: $($_.Exception.Message)" -ForegroundColor Green
2525
Write-Host ("⚡PowerShellGet update skipped: {0}" -f $_.Exception.Message) -ForegroundColor Green
2626
}
2727
try {
28-
Install-Module -Name PackageManagement -Force -Scope CurrentUser -ErrorAction Stop
28+
Install-Module -Name PackageManagement -Force -Scope CurrentUser -ErrorAction Continue
2929
} catch {
3030
#Write-Verbose "⚡PackageManagement update skipped: $($_.Exception.Message)" -ForegroundColor Yellow
3131
Write-Host ("⚡PackageManagement update skipped: {0}" -f $_.Exception.Message) -ForegroundColor Yellow
@@ -34,20 +34,20 @@ Function Start-MyCommands {
3434
Write-Host "⚡Ensuring AADInternals and AADInternals-Endpoints present and up to date..." -ForegroundColor Green
3535
$modules = @('AADInternals', 'AADInternals-Endpoints')
3636
foreach($m in $modules) {
37-
$installed = Get-InstalledModule -Name $m -ErrorAction SilentlyContinue
37+
$installed = Get-InstalledModule -Name $m -ErrorAction Continue
3838
if (-not $installed) {
3939
Write-Host "⚡Installing $m" -ForegroundColor Green
40-
Install-Module -Name $m -Scope CurrentUser -Force -ErrorAction Stop
40+
Install-Module -Name $m -Scope CurrentUser -Force -ErrorAction Continue
4141
} else {
42-
$remote = Find-Module -Name $m -ErrorAction SilentlyContinue
42+
$remote = Find-Module -Name $m -ErrorAction Continue
4343
if ($remote -and ($remote.Version -gt $installed.Version)) {
4444
Write-Host "⚡Updating $m (local $($installed.Version) -> remote $($remote.Version))" -ForegroundColor Green
45-
Update-Module -Name $m -Force -ErrorAction Stop
45+
Update-Module -Name $m -Force -ErrorAction Continue
4646
} else {
4747
Write-Host "$m is up to date" -ForegroundColor Green
4848
}
4949
}
50-
Import-Module -Name $m -ErrorAction Stop
50+
Import-Module -Name $m -ErrorAction Continue
5151
}
5252
# install the AD GUI+tools capability (includes ADUC)
5353
Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0
@@ -69,13 +69,13 @@ Function Start-MyCommands {
6969
Start-Sleep -Seconds 2
7070

7171
Write-Host "⚡Installing or updating DSInternals..." -ForegroundColor Green
72-
if (-not(Get-InstalledModule -Name DSInternals -ErrorAction SilentlyContinue)) {
73-
Install-Module -Name DSInternals -Scope CurrentUser -Force -ErrorAction Stop
72+
if (-not(Get-InstalledModule -Name DSInternals -ErrorAction Continue)) {
73+
Install-Module -Name DSInternals -Scope CurrentUser -Force -ErrorAction Continue
7474
} else {
7575
$local = Get-InstalledModule -Name DSInternals
76-
$remote = Find-Module -Name DSInternals -ErrorAction SilentlyContinue
76+
$remote = Find-Module -Name DSInternals -ErrorAction Continue
7777
if ($remote -and($remote.Version -gt $local.Version)) {
78-
Update-Module -Name DSInternals -Force -ErrorAction Stop
78+
Update-Module -Name DSInternals -Force -ErrorAction Continue
7979
}
8080
}
8181
#Wait for availability with timeout
@@ -89,7 +89,7 @@ Function Start-MyCommands {
8989
if ($elapsed -ge $timeout) {
9090
Write-Warning "⚡Timeout waiting for DSInternals module" -ForegroundColor Yellow
9191
}
92-
Import-Module -Name DSInternals -ErrorAction SilentlyContinue
92+
Import-Module -Name DSInternals -ErrorAction Continue
9393

9494
if ($pv.Major -ge 7) {
9595
# PowerShell 7 or later
@@ -106,7 +106,7 @@ Function Start-MyCommands {
106106
}
107107
$psReflectPath = Join-Path -Path $scriptRoot -ChildPath 'PSReflect\PSReflect.psm1'
108108
if (Test-Path $psReflectPath) {
109-
Import-Module -Name $psReflectPath -ErrorAction Stop
109+
Import-Module -Name $psReflectPath -ErrorAction Continue
110110
Write-Host "⚡PSReflect loaded from $psReflectPath" -ForegroundColor Green
111111
} else {
112112
#Write-Warning "⚡PSReflect module not found at $psReflectPath" -ForegroundColor Yellow
@@ -139,21 +139,28 @@ Function Start-MyCommands {
139139
Get-InstalledModule | ForEach-Object {
140140
$name = $_.Name
141141
try {
142-
Update-Module -Name $name -Force -ErrorAction Stop
142+
Update-Module -Name $name -Force -ErrorAction Continue
143143
Write-Host "⚡Updated $name" -ForegroundColor Green
144144
} catch {
145145
Write-Host ("⚡Failed {0}: {1}" -f $name, $_.Exception.Message) -ForegroundColor Yellow
146146
}
147147
}
148148
}
149+
150+
Write-Host "⚡Installing Azure Automation CLI extension" -ForegroundColor Green
151+
az extension add -n automation
152+
153+
Write-Host "⚡Enables automatic, silent installation of missing CLI extensions when you run a command for the first time" -ForegroundColor Green
154+
az config set extension.use_dynamic_install=yes_without_prompt
149155

150156
Write-Host "⚡PowerView Runs much better in an older PS - RUN the following..." -ForegroundColor Green
151157
Write-Host "⚡powershell.exe -Version 5.1" -ForegroundColor Green
152158
Write-Host "⚡.\kickoff.ps1" -ForegroundColor Green
153159
Write-Host "⚡ PowerSploit\Recon> . .\PowerView.ps1" -ForegroundColor Green
160+
161+
Get-AzContext
154162

155163
}
156164
Start-MyCommands
157165

158166
Get-Module -Name AADInternals, AADInternals-Endpoints, DSInternals, ActiveDirectory, PSPreworkout, PSReflect, PowerView -ErrorAction SilentlyContinue
159-

0 commit comments

Comments
 (0)