-
Notifications
You must be signed in to change notification settings - Fork 5
/
New-Target.psm1
53 lines (43 loc) · 1.61 KB
/
New-Target.psm1
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
function New-Target{
<#
.SYNOPSIS
Creates a new target to be targeted
.DESCRIPTION
Creates a new target to be targeted
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)][string[]]$Target
)
# Confirm if creds variable is set
if ($cred -eq $null){
$cred = Get-Credential
}
# Iterate through the input target and setup sessions
foreach ($endpoint in $Target){
# Check if already in list
if($GlobalTargetList.ContainsKey($endpoint)){
$message = "Target " + $endpoint + " already exists"
Write-HostHunterInformation -MessageData $message
}else{
$targets = $endpoint
if($GlobalTargetList.Count -ge 1){
# Extract each target name
foreach($targettobeadded in $GlobalTargetList.Values){
Write-Host $targettobeadded.PSSession.ComputerName
$targets = $targets + "," + $targettobeadded.PSSession.ComputerName
}
}
Write-Host $targets
# Notify user
$message = "Adding " + $endpoint + " to TrustedHosts list"
Write-HostHunterInformation -MessageData $message -ForegroundColor "Green"
# Set the trusted hosts registry key
Set-Item WSMan:\localhost\Client\TrustedHosts $targets -Force
# Now create the endpoint session
New-EndpointSession -Target $endpoint -Credential $cred
}
}
# At the end of adding them all all, give the user a list of targets
Get-TargetList
}