Skip to content

Commit 4cc610c

Browse files
authored
Add files via upload
1 parent 67f789d commit 4cc610c

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

generic/kickoff.ps1

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
Set-Location "C:\Users\mcontestabile\blahblah"
2+
3+
# Determine PSVersion once
4+
$pv = $PSVersionTable.PSVersion
5+
Write-Host "⚡Showing PowerShell version..." -ForegroundColor Green
6+
$PSVersionTable | Format-Table -AutoSize
7+
8+
Function Start-MyCommands {
9+
10+
Write-Host "⚡Executing startup tasks..." -ForegroundColor Green
11+
#Ensure PSGallery exists and is trusted
12+
if (-not(Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) {
13+
Register-PSRepository -Name PSGallery -SourceLocation 'https://www.powershellgallery.com/api/v2' -InstallationPolicy Trusted
14+
} else {
15+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
16+
}
17+
#Safer execution policy for user scope
18+
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force
19+
20+
#Update PowerShellGet / PackageManagement to avoid missing parameter issues
21+
try {
22+
Install-Module -Name PowerShellGet -Force -Scope CurrentUser -ErrorAction Stop
23+
} catch {
24+
Write-Verbose "⚡PowerShellGet update skipped: $($_.Exception.Message)" -ForegroundColor Green
25+
}
26+
try {
27+
Install-Module -Name PackageManagement -Force -Scope CurrentUser -ErrorAction Stop
28+
} catch {
29+
Write-Verbose "⚡PackageManagement update skipped: $($_.Exception.Message)" -ForegroundColor Yellow
30+
}
31+
32+
Write-Host "⚡Ensuring AADInternals and AADInternals-Endpoints present and up to date..." -ForegroundColor Green
33+
$modules = @('AADInternals', 'AADInternals-Endpoints')
34+
foreach($m in $modules) {
35+
$installed = Get-InstalledModule -Name $m -ErrorAction SilentlyContinue
36+
if (-not $installed) {
37+
Write-Host "⚡Installing $m" -ForegroundColor Green
38+
Install-Module -Name $m -Scope CurrentUser -Force -ErrorAction Stop
39+
} else {
40+
$remote = Find-Module -Name $m -ErrorAction SilentlyContinue
41+
if ($remote -and ($remote.Version -gt $installed.Version)) {
42+
Write-Host "⚡Updating $m (local $($installed.Version) -> remote $($remote.Version))" -ForegroundColor Green
43+
Update-Module -Name $m -Force -ErrorAction Stop
44+
} else {
45+
Write-Host "$m is up to date" -ForegroundColor Green
46+
}
47+
}
48+
Import-Module -Name $m -ErrorAction Stop
49+
}
50+
51+
Write-Host "⚡Listing Active Directory Module part of RSAT..." -ForegroundColor Green
52+
Get-Module ActiveDirectory -ListAvailable
53+
Write-Host "⚡Showing RSAT version..." -ForegroundColor Green
54+
Get-WindowsCapability -Name 'RSAT.ActiveDirectory*' -Online
55+
56+
Write-Host "⚡Showing Azure PowerShell version..." -ForegroundColor Green
57+
Get-InstalledModule -Name Az | Format-Table -AutoSize
58+
Start-Sleep -Seconds 2
59+
60+
Write-Host "⚡Installing or updating DSInternals..." -ForegroundColor Green
61+
if (-not(Get-InstalledModule -Name DSInternals -ErrorAction SilentlyContinue)) {
62+
Install-Module -Name DSInternals -Scope CurrentUser -Force -ErrorAction Stop
63+
} else {
64+
$local = Get-InstalledModule -Name DSInternals
65+
$remote = Find-Module -Name DSInternals -ErrorAction SilentlyContinue
66+
if ($remote -and($remote.Version -gt $local.Version)) {
67+
Update-Module -Name DSInternals -Force -ErrorAction Stop
68+
}
69+
}
70+
#Wait for availability with timeout
71+
$timeout = 30;
72+
$elapsed = 0
73+
while (-not(Get-Module -Name DSInternals -ListAvailable) -and($elapsed -lt $timeout)) {
74+
Write-Host "⚡Waiting for DSInternals to become available..." -ForegroundColor Yellow
75+
Start-Sleep -Seconds 2;
76+
$elapsed += 2
77+
}
78+
if ($elapsed -ge $timeout) {
79+
Write-Warning "⚡Timeout waiting for DSInternals module" -ForegroundColor Yellow
80+
}
81+
Import-Module -Name DSInternals -ErrorAction SilentlyContinue
82+
83+
if ($pv.Major -ge 7) {
84+
# PowerShell 7 or later
85+
Write-Host "⚡Running PowerShell $($pv.ToString()) — using PowerShell 7+ path not loading PowerSploit" -ForegroundColor Green
86+
}elseif ($pv.Major -eq 5 -and $pv.Minor -eq 1) {
87+
# Exactly Windows PowerShell 5.1
88+
Write-Host "⚡Running Windows PowerShell $($pv.ToString()) — using 5.1 path - loading PSReflect and PowerSploit" -ForegroundColor Green
89+
90+
#Import PSReflect by absolute path relative to script location
91+
$scriptRoot = if ($PSScriptRoot) {
92+
$PSScriptRoot
93+
} else {
94+
$PWD.Path
95+
}
96+
$psReflectPath = Join-Path -Path $scriptRoot -ChildPath 'PSReflect\PSReflect.psm1'
97+
if (Test-Path $psReflectPath) {
98+
Import-Module -Name $psReflectPath -ErrorAction Stop
99+
Write-Host "⚡PSReflect loaded from $psReflectPath" -ForegroundColor Green
100+
} else {
101+
Write-Warning "⚡PSReflect module not found at $psReflectPath" -ForegroundColor Yellow
102+
}
103+
104+
#Import PowerView script by full path(dot - source.ps1 or Import-Module only for psm1 / dll)
105+
$powerViewPath = Join-Path -Path $scriptRoot -ChildPath 'PowerSploit\Recon\PowerView.ps1'
106+
if (Test-Path $powerViewPath) {
107+
.$powerViewPath #dot - source a script to import functions into session
108+
Write-Host "⚡PowerView dot-sourced from $powerViewPath" -ForegroundColor Green
109+
} else {
110+
Write-Warning "⚡PowerView not found at $powerViewPath" -ForegroundColor Yellow
111+
}
112+
}else{
113+
# Any other PowerShell version
114+
Write-Host "⚡Running PowerShell $($pv.ToString()) — using fallback path - not loading PowerSploit" -ForegroundColor Yellow
115+
# place fallback code here
116+
}
117+
118+
Write-Host "⚡Installing PSPreworkout" -ForegroundColor Green
119+
Install-Module -Name PSPreworkout -Scope CurrentUser -Force -AllowClobber
120+
Write-Host "⚡Checking for updates" -ForegroundColor Green
121+
Get-ModulesWithUpdate -PassThru
122+
123+
$response = Read-Host "Apply module updates? (Y/N)"
124+
if ($response.ToUpper() -eq 'Y') {
125+
Write-Host "⚡Applying updates" -ForegroundColor Green
126+
Get-InstalledModule | ForEach-Object {
127+
$name = $_.Name
128+
try {
129+
Update-Module -Name $name -Force -ErrorAction Stop
130+
Write-Host "⚡Updated $name" -ForegroundColor Green
131+
} catch {
132+
Write-Host ("⚡Failed {0}: {1}" -f $name, $_.Exception.Message) -ForegroundColor Yellow
133+
}
134+
}
135+
}
136+
137+
Write-Host "⚡PowerView Runs much better in an older PS - RUN the following..." -ForegroundColor Green
138+
Write-Host "⚡powershell.exe -Version 5.1" -ForegroundColor Green
139+
Write-Host "⚡.\kickoff.ps1" -ForegroundColor Green
140+
Write-Host "⚡ PowerSploit\Recon> . .\PowerView.ps1" -ForegroundColor Green
141+
142+
}
143+
Start-MyCommands
144+
145+
Get-Module -Name AADInternals, AADInternals-Endpoints, DSInternals, ActiveDirectory, PSPreworkout, PSReflect, PowerView -ErrorAction SilentlyContinue

0 commit comments

Comments
 (0)