1- Set-Location " C:\Users\something that works for you "
1+ Set-Location " C:\Users\cyberadmin\Desktop "
22
33# Determine PSVersion once
44$pv = $PSVersionTable.PSVersion
@@ -16,79 +16,57 @@ Function Start-MyCommands {
1616 }
1717 # Safer execution policy for user scope
1818 Set-ExecutionPolicy - Scope CurrentUser - ExecutionPolicy RemoteSigned - Force
19+
20+ Write-Host " ⚡Installing ...RSAT-AD-PowerShell" - ForegroundColor Green
21+ Install-WindowsFeature - Name RSAT- AD- PowerShell
1922
20- # Update PowerShellGet / PackageManagement to avoid missing parameter issues
21- try {
22- Install-Module - Name PowerShellGet - Force - Scope CurrentUser - ErrorAction Continue
23- } catch {
24- # Write-Verbose "⚡PowerShellGet update skipped: $($_.Exception.Message)" -ForegroundColor Green
25- Write-Host (" ⚡PowerShellGet update skipped: {0}" -f $_.Exception.Message ) - ForegroundColor Green
26- }
27- try {
28- Install-Module - Name PackageManagement - Force - Scope CurrentUser - ErrorAction Continue
29- } catch {
30- # Write-Verbose "⚡PackageManagement update skipped: $($_.Exception.Message)" -ForegroundColor Yellow
31- Write-Host (" ⚡PackageManagement update skipped: {0}" -f $_.Exception.Message ) - ForegroundColor Yellow
32- }
23+ Write-Host " ⚡Installing ...NuGet provider" - ForegroundColor Green
24+ Install-PackageProvider - Name NuGet - Force - Scope AllUsers
3325
34- Write-Host " ⚡Ensuring AADInternals and AADInternals-Endpoints present and up to date ..." - ForegroundColor Green
35- $modules = @ ( ' AADInternals ' , ' AADInternals-Endpoints ' )
36- foreach ( $m in $modules ) {
37- $installed = Get-InstalledModule - Name $m - ErrorAction Continue
38- if ( -not $installed ) {
39- Write-Host " ⚡Installing $m " - ForegroundColor Green
40- Install-Module - Name $m - Scope CurrentUser - Force - ErrorAction Continue
41- } else {
42- $remote = Find-Module - Name $m - ErrorAction Continue
43- if ( $remote -and ( $remote .Version -gt $installed .Version )) {
44- Write-Host " ⚡Updating $m (local $ ( $installed .Version ) -> remote $ ( $remote .Version ) ) " - ForegroundColor Green
45- Update-Module - Name $m - Force - ErrorAction Continue
46- } else {
47- Write-Host " ⚡ $m is up to date " - ForegroundColor Green
48- }
49- }
50- Import-Module - Name $m - ErrorAction Continue
51- }
52- # install the AD GUI+tools capability (includes ADUC)
26+ Write-Host " ⚡Installing ...PowerShellGet " - ForegroundColor Green
27+ Install-Module - Name PowerShellGet - Force - Scope AllUsers
28+
29+ Write-Host " ⚡Installing ...PackageManagement " - ForegroundColor Green
30+ Install-Module - Name PackageManagement - Force - Scope AllUsers - AllowClobber
31+
32+ Write-Host " ⚡Installing ...AADInternals " - ForegroundColor Green
33+ Install-Module - Name AADInternals - Scope AllUsers - Force - AllowClobber
34+
35+ Write-Host " ⚡Installing ...AADInternals-Endpoints " - ForegroundColor Green
36+ Install-Module - Name ' AADInternals-Endpoints ' - Scope AllUsers - Force - AllowClobber
37+
38+ Write-Host " ⚡Importing ...AADInternals " - ForegroundColor Green
39+ Import-Module AADInternals
40+
41+ Write-Host " ⚡Importing ...AADInternals-Endpoints " - ForegroundColor Green
42+ Import-Module ' AADInternals-Endpoints '
43+
44+ Write-Host " ⚡Add-WindowsCapability ...Rsat.ActiveDirectory " - ForegroundColor Green
5345 Add-WindowsCapability - Online - Name Rsat.ActiveDirectory.DS- LDS.Tools~~~~0.0 .1.0
5446
55- # install the AD PowerShell module (if separate on your build)
47+ Write-Host " ⚡Add-WindowsCapability ...Rsat.AD " - ForegroundColor Green
5648 Add-WindowsCapability - Online - Name Rsat.AD.PowerShell~~~~0.0 .1.0
5749
58- # load the module into the current session
50+ Write-Host " ⚡Importing ...ActiveDirectory " - ForegroundColor Green
5951 Import-Module ActiveDirectory
6052
61-
6253 Write-Host " ⚡Listing Active Directory Module part of RSAT..." - ForegroundColor Green
6354 Get-Module ActiveDirectory - ListAvailable
55+
6456 Write-Host " ⚡Showing RSAT version..." - ForegroundColor Green
6557 Get-WindowsCapability - Name ' RSAT.ActiveDirectory*' - Online
58+
59+ Write-Host " ⚡Installing ...Az" - ForegroundColor Green
60+ Install-Module - Name Az - Scope AllUsers - AllowClobber - Force
6661
6762 Write-Host " ⚡Showing Azure PowerShell version..." - ForegroundColor Green
6863 Get-InstalledModule - Name Az | Format-Table - AutoSize
6964 Start-Sleep - Seconds 2
7065
71- Write-Host " ⚡Installing or updating DSInternals..." - ForegroundColor Green
72- if (-not (Get-InstalledModule - Name DSInternals - ErrorAction Continue )) {
73- Install-Module - Name DSInternals - Scope CurrentUser - Force - ErrorAction Continue
74- } else {
75- $local = Get-InstalledModule - Name DSInternals
76- $remote = Find-Module - Name DSInternals - ErrorAction Continue
77- if ($remote -and ($remote.Version -gt $local.Version )) {
78- Update-Module - Name DSInternals - Force - ErrorAction Continue
79- }
80- }
81- # Wait for availability with timeout
82- $timeout = 30 ;
83- $elapsed = 0
84- while (-not (Get-Module - Name DSInternals - ListAvailable) -and ($elapsed -lt $timeout )) {
85- Write-Host " ⚡Waiting for DSInternals to become available..." - ForegroundColor Yellow
86- Start-Sleep - Seconds 2 ;
87- $elapsed += 2
88- }
89- if ($elapsed -ge $timeout ) {
90- Write-Warning " ⚡Timeout waiting for DSInternals module" - ForegroundColor Yellow
91- }
66+ Write-Host " ⚡Installing ...DSInternals" - ForegroundColor Green
67+ Install-Module - Name DSInternals - Scope AllUsers - AllowClobber - Force
68+
69+ Write-Host " ⚡Importing ...DSInternals" - ForegroundColor Green
9270 Import-Module - Name DSInternals - ErrorAction Continue
9371
9472 if ($pv.Major -ge 7 ) {
@@ -109,7 +87,6 @@ Function Start-MyCommands {
10987 Import-Module - Name $psReflectPath - ErrorAction Continue
11088 Write-Host " ⚡PSReflect loaded from $psReflectPath " - ForegroundColor Green
11189 } else {
112- # Write-Warning "⚡PSReflect module not found at $psReflectPath" -ForegroundColor Yellow
11390 Write-Host (" ⚡PSReflect module not found at: {0}" -f $psReflectPath ) - ForegroundColor Yellow
11491 }
11592
@@ -119,7 +96,6 @@ Function Start-MyCommands {
11996 .$powerViewPath # dot - source a script to import functions into session
12097 Write-Host " ⚡PowerView dot-sourced from $powerViewPath " - ForegroundColor Green
12198 } else {
122- # Write-Warning "⚡PowerView not found at $powerViewPath" -ForegroundColor Yellow
12399 Write-Host (" ⚡PowerView module not found at: {0}" -f $powerViewPath ) - ForegroundColor Yellow
124100 }
125101 }else {
@@ -130,6 +106,7 @@ Function Start-MyCommands {
130106
131107 Write-Host " ⚡Installing PSPreworkout" - ForegroundColor Green
132108 Install-Module - Name PSPreworkout - Scope CurrentUser - Force - AllowClobber
109+
133110 Write-Host " ⚡Checking for updates" - ForegroundColor Green
134111 Get-ModulesWithUpdate - PassThru
135112
@@ -147,11 +124,14 @@ Function Start-MyCommands {
147124 }
148125 }
149126
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
127+ if (Get-Command az - ErrorAction SilentlyContinue) {
128+ Write-Host " ⚡Installing Azure Automation CLI extension" - ForegroundColor Green
129+ az extension add - n automation
130+ Write-Host " ⚡Enables automatic, silent installation of missing CLI extensions when you run a command for the first time" - ForegroundColor Green
131+ az config set extension.use_dynamic_install= yes_without_prompt
132+ } else {
133+ Write-Host " Azure CLI (az) not found; skipping az extension commands" - ForegroundColor Yellow
134+ }
155135
156136 Write-Host " ⚡PowerView Runs much better in an older PS - RUN the following..." - ForegroundColor Green
157137 Write-Host " ⚡powershell.exe -Version 5.1" - ForegroundColor Green
@@ -164,4 +144,3 @@ Function Start-MyCommands {
164144Start-MyCommands
165145
166146Get-Module - Name AADInternals, AADInternals- Endpoints, DSInternals, ActiveDirectory, PSPreworkout, PSReflect, PowerView - ErrorAction SilentlyContinue
167-
0 commit comments