vagrant-windows-domain 1.3.2 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vagrant-windows-domain/templates/runner.ps1.erb +177 -15
- data/lib/vagrant-windows-domain/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbdaa30870420b7e0fc8c44c2716a0bf97f5067114f276f391a6147ef6d29c7a
|
4
|
+
data.tar.gz: 52db0ec2e6a68ef743f10720d0c03add6844c59e31f6a6e974db046d10c187cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6915697baa4d5922ad0c33b17466e0d01f5dc92ab26fbe295aa6009bd50c4d3b3d79234460d3b3368f90a02b93db51c9b33c176967311e3a7087ec3b984f4a3c
|
7
|
+
data.tar.gz: b1dc722b9620aeeb3a03870c063351d79161af9931f603cfcf389c06e23685a5716ae71c3921f852debb772ad8006d4b72447b2d5b90f4ae6565c9ff7cbcdeb8
|
@@ -17,6 +17,179 @@ function Repair-OpenSSHPasswd(){
|
|
17
17
|
$passwd | Set-Content $passwdPath -Encoding Ascii
|
18
18
|
}
|
19
19
|
}
|
20
|
+
function New-ADSIPrincipalContext
|
21
|
+
{
|
22
|
+
[CmdletBinding(SupportsShouldProcess = $true)]
|
23
|
+
[OutputType('System.DirectoryServices.AccountManagement.PrincipalContext')]
|
24
|
+
PARAM
|
25
|
+
(
|
26
|
+
[Alias("RunAs")]
|
27
|
+
[System.Management.Automation.PSCredential]
|
28
|
+
[System.Management.Automation.Credential()]
|
29
|
+
$Credential = [System.Management.Automation.PSCredential]::Empty,
|
30
|
+
|
31
|
+
[Parameter(Mandatory = $true)]
|
32
|
+
[System.DirectoryServices.AccountManagement.ContextType]$ContextType,
|
33
|
+
|
34
|
+
$DomainName = [System.DirectoryServices.ActiveDirectory.Domain]::Getcurrentdomain(),
|
35
|
+
|
36
|
+
$Container,
|
37
|
+
|
38
|
+
[System.DirectoryServices.AccountManagement.ContextOptions[]]$ContextOptions
|
39
|
+
)
|
40
|
+
|
41
|
+
BEGIN
|
42
|
+
{
|
43
|
+
$ScriptName = (Get-Variable -name MyInvocation -Scope 0 -ValueOnly).MyCommand
|
44
|
+
Write-Verbose -Message "[$ScriptName] Add Type System.DirectoryServices.AccountManagement"
|
45
|
+
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
|
46
|
+
}
|
47
|
+
PROCESS
|
48
|
+
{
|
49
|
+
TRY
|
50
|
+
{
|
51
|
+
switch ($ContextType)
|
52
|
+
{
|
53
|
+
"Domain" { $ArgumentList = $ContextType, $DomainName }
|
54
|
+
"Machine" { $ArgumentList = $ContextType, $ComputerName }
|
55
|
+
"ApplicationDirectory" { $ArgumentList = $ContextType }
|
56
|
+
}
|
57
|
+
|
58
|
+
IF ($PSBoundParameters['Container'])
|
59
|
+
{
|
60
|
+
$ArgumentList += $Container
|
61
|
+
}
|
62
|
+
|
63
|
+
IF ($PSBoundParameters['ContextOptions'])
|
64
|
+
{
|
65
|
+
$ArgumentList += $($ContextOptions)
|
66
|
+
}
|
67
|
+
|
68
|
+
IF ($PSBoundParameters['Credential'])
|
69
|
+
{
|
70
|
+
# Query the specified domain or current if not entered, with the specified credentials
|
71
|
+
$ArgumentList += $($Credential.UserName), $($Credential.GetNetworkCredential().password)
|
72
|
+
}
|
73
|
+
|
74
|
+
IF ($PSCmdlet.ShouldProcess($DomainName, "Create Principal Context"))
|
75
|
+
{
|
76
|
+
# Query
|
77
|
+
New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ArgumentList
|
78
|
+
}
|
79
|
+
} #TRY
|
80
|
+
CATCH
|
81
|
+
{
|
82
|
+
$PSCmdlet.ThrowTerminatingError($_)
|
83
|
+
}
|
84
|
+
} #PROCESS
|
85
|
+
}
|
86
|
+
|
87
|
+
function Get-ADSIComputer
|
88
|
+
{
|
89
|
+
[CmdletBinding(DefaultParameterSetName="All")]
|
90
|
+
param ([Parameter(Mandatory=$true,ParameterSetName="Identity")]
|
91
|
+
[string]$Identity,
|
92
|
+
|
93
|
+
[Alias("RunAs")]
|
94
|
+
[System.Management.Automation.PSCredential]
|
95
|
+
[System.Management.Automation.Credential()]
|
96
|
+
$Credential = [System.Management.Automation.PSCredential]::Empty,
|
97
|
+
|
98
|
+
[String]$DomainName
|
99
|
+
)
|
100
|
+
BEGIN
|
101
|
+
{
|
102
|
+
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
|
103
|
+
|
104
|
+
# Create Context splatting
|
105
|
+
$ContextSplatting = @{ ContextType = "Domain" }
|
106
|
+
|
107
|
+
IF ($PSBoundParameters['Credential']) { $ContextSplatting.Credential = $Credential }
|
108
|
+
IF ($PSBoundParameters['DomainName']) { $ContextSplatting.DomainName = $DomainName }
|
109
|
+
|
110
|
+
$Context = New-ADSIPrincipalContext @ContextSplatting
|
111
|
+
|
112
|
+
}
|
113
|
+
PROCESS
|
114
|
+
{
|
115
|
+
TRY{
|
116
|
+
IF($Identity)
|
117
|
+
{
|
118
|
+
[System.DirectoryServices.AccountManagement.ComputerPrincipal]::FindByIdentity($Context, $Identity)
|
119
|
+
}
|
120
|
+
ELSE{
|
121
|
+
$ComputerPrincipal = New-object -TypeName System.DirectoryServices.AccountManagement.ComputerPrincipal -ArgumentList $Context
|
122
|
+
$Searcher = new-object System.DirectoryServices.AccountManagement.PrincipalSearcher
|
123
|
+
$Searcher.QueryFilter = $ComputerPrincipal
|
124
|
+
|
125
|
+
$Searcher.FindAll()
|
126
|
+
}
|
127
|
+
}
|
128
|
+
CATCH
|
129
|
+
{
|
130
|
+
$pscmdlet.ThrowTerminatingError($_)
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
function Remove-ADSIComputer
|
136
|
+
{
|
137
|
+
[CmdletBinding(SupportsShouldProcess = $true)]
|
138
|
+
PARAM (
|
139
|
+
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true)]
|
140
|
+
$Identity,
|
141
|
+
|
142
|
+
[Alias("RunAs")]
|
143
|
+
[System.Management.Automation.PSCredential]
|
144
|
+
[System.Management.Automation.Credential()]
|
145
|
+
$Credential = [System.Management.Automation.PSCredential]::Empty,
|
146
|
+
|
147
|
+
[String]$DomainName,
|
148
|
+
|
149
|
+
[Switch]$Recursive
|
150
|
+
)
|
151
|
+
|
152
|
+
BEGIN
|
153
|
+
{
|
154
|
+
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
|
155
|
+
|
156
|
+
# Create Context splatting
|
157
|
+
$ContextSplatting = @{ }
|
158
|
+
IF ($PSBoundParameters['Credential']) { $ContextSplatting.Credential = $Credential }
|
159
|
+
IF ($PSBoundParameters['DomainName']) { $ContextSplatting.DomainName = $DomainName }
|
160
|
+
|
161
|
+
}
|
162
|
+
PROCESS
|
163
|
+
{
|
164
|
+
TRY
|
165
|
+
{
|
166
|
+
# Not Recursive
|
167
|
+
if (-not $PSBoundParameters['Recursive'])
|
168
|
+
{
|
169
|
+
if ($pscmdlet.ShouldProcess("$Identity", "Remove Account"))
|
170
|
+
{
|
171
|
+
$Account = Get-ADSIComputer -Identity $Identity @ContextSplatting
|
172
|
+
$Account.delete()
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
# Recursive (if the computer is the parent of one leaf or more)
|
177
|
+
if ($PSBoundParameters['Recursive'])
|
178
|
+
{
|
179
|
+
if ($pscmdlet.ShouldProcess("$Identity", "Remove Account and any child objects"))
|
180
|
+
{
|
181
|
+
$Account = Get-ADSIComputer -Identity $Identity @ContextSplatting
|
182
|
+
$Account.GetUnderlyingObject().deletetree()
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
}
|
187
|
+
CATCH
|
188
|
+
{
|
189
|
+
$pscmdlet.ThrowTerminatingError($_)
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
20
193
|
<% if options[:computer_name] != nil %>
|
21
194
|
$computerName='<%= options[:computer_name] %>'
|
22
195
|
<% else %>
|
@@ -87,26 +260,15 @@ if (Test-PartOfDomain -computerName $computerName -domain $domain){
|
|
87
260
|
<% end %>
|
88
261
|
|
89
262
|
Repair-OpenSSHPasswd
|
90
|
-
|
91
|
-
# Fix vagrant-windows GH-129, if there's an existing scheduled
|
92
|
-
# reboot cancel it so shutdown succeeds
|
93
|
-
#&shutdown /a
|
94
|
-
|
95
|
-
# Force shutdown the machine now
|
96
|
-
#&shutdown /r /t 0 /c "Vagrant Halt" /f /d p:4:1
|
97
263
|
}
|
98
264
|
<% else %>
|
99
265
|
if (!(Test-JoinedToADomain)) {
|
100
266
|
Throw "$computerName not part of any domain"
|
101
267
|
} else {
|
102
|
-
|
268
|
+
#When destroying the vagrant machine, the goal is not as much to have the virtual machine disjoin from the domain, but to remove the computer object associated with the
|
269
|
+
#machine so that future runs of vagrant up will succeed (especially when the vagrantfile explicitly defines a computer name. That being the case, the remove-computer
|
270
|
+
#command has been replaced with a custom function which is able to remove the computer object associated with the vagrant machine in active directory.
|
271
|
+
Remove-ADSIComputer -Identity $env:COMPUTERNAME -DomainName $domain -Credential $credentials -Verbose
|
103
272
|
Repair-OpenSSHPasswd
|
104
|
-
#removed the shutdown of the vm when disjoining it from the domain since, as the vm is about to be destroyed anyway, so there is no use for it.
|
105
|
-
# Fix vagrant-windows GH-129, if there's an existing scheduled
|
106
|
-
# reboot cancel it so shutdown succeeds
|
107
|
-
#&shutdown /a
|
108
|
-
|
109
|
-
# Force shutdown the machine now
|
110
|
-
#&shutdown /r /t 0 /c "Vagrant Halt" /f /d p:4:1
|
111
273
|
}
|
112
274
|
<% end %>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-windows-domain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Fellows
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|