-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvoke-test.ps1
More file actions
40 lines (33 loc) · 1.57 KB
/
invoke-test.ps1
File metadata and controls
40 lines (33 loc) · 1.57 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
#name of target VM
$MyVM = CHANGEME
#Guest VM Credentials
$guestAdmin = "CHANGEME"
$guestPassword = ConvertTo-SecureString “CHANGEME” -AsPlainText -Force
$guestCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $guestAdmin, $guestPassword
#Guest VM domain Credentials
$DomainAccountPWD = 'CHANGEME'
$userID = 'CHANGEME'
#Works but requires WinRM and CredSSP configuration
$ScriptText01 = "
`$username = CHANGEME
`$pass = 'CHANGEME'
`$cred = New-Object System.Managment.Automation.PSCredential -ArgumentList @(`$username,(ConvertTo-SecureString -String `$pass -Asplaintext -Force))
invoke-command -Computername QWS01 -ScriptBlock {C:\Users\CHANGEME\Desktop\test.ps1} -Authentication Credssp -Credential `$cred
"
#create new .ps file to run
$ScriptText02 = "
echo `"```$domain = `'quarantine`'
```$password = `'$DomainAccountPWD`' | ConvertTo-SecureString -asPlainText -force;
```$username = `'$userID`';
```$credential = New-Object System.Management.Automation.PSCredential(```$username, ```$password);
Add-computer -DomainName ```$domain -Credential ```$credential`" > C:\Users\CHANGEME\Desktop\test.ps1
"
#attempt domain join directly from console
$ScriptText03 = @"
`$domain = "quarantine"
`$password = "$DomainAccountPWD" | ConvertTo-SecureString -asPlainText -force;
`$username = "$userID";
`$credential = New-Object System.Management.Automation.PSCredential(`$username, `$password);
Add-computer -DomainName `$domain -Credential `$credential
"@
Invoke-VMScript -ScriptText $ScriptText02 -vm $MyVM -GuestCredential $guestCredential -ScriptType Powershell