Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
040ff070
Commit
040ff070
authored
Jun 14, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioner/powershell
parent
cf570a71
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1234 additions
and
0 deletions
+1234
-0
plugin/provisioner-powershell/main.go
plugin/provisioner-powershell/main.go
+15
-0
provisioner/powershell/elevated.go
provisioner/powershell/elevated.go
+87
-0
provisioner/powershell/powershell.go
provisioner/powershell/powershell.go
+17
-0
provisioner/powershell/provisioner.go
provisioner/powershell/provisioner.go
+459
-0
provisioner/powershell/provisioner_test.go
provisioner/powershell/provisioner_test.go
+656
-0
No files found.
plugin/provisioner-powershell/main.go
0 → 100644
View file @
040ff070
package
main
import
(
"github.com/mitchellh/packer/packer/plugin"
"github.com/mitchellh/packer/provisioner/powershell"
)
func
main
()
{
server
,
err
:=
plugin
.
Server
()
if
err
!=
nil
{
panic
(
err
)
}
server
.
RegisterProvisioner
(
new
(
powershell
.
Provisioner
))
server
.
Serve
()
}
provisioner/powershell/elevated.go
0 → 100644
View file @
040ff070
package
powershell
import
(
"text/template"
)
type
elevatedOptions
struct
{
User
string
Password
string
TaskName
string
TaskDescription
string
EncodedCommand
string
}
var
elevatedTemplate
=
template
.
Must
(
template
.
New
(
"ElevatedCommand"
)
.
Parse
(
`
$name = "{{.TaskName}}"
$log = "$env:TEMP\$name.out"
$s = New-Object -ComObject "Schedule.Service"
$s.Connect()
$t = $s.NewTask($null)
$t.XmlText = @'
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Description>{{.TaskDescription}}</Description>
</RegistrationInfo>
<Principals>
<Principal id="Author">
<UserId>{{.User}}</UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT24H</ExecutionTimeLimit>
<Priority>4</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>cmd</Command>
<Arguments>/c powershell.exe -EncodedCommand {{.EncodedCommand}} > %TEMP%\{{.TaskName}}.out 2>&1</Arguments>
</Exec>
</Actions>
</Task>
'@
$f = $s.GetFolder("\")
$f.RegisterTaskDefinition($name, $t, 6, "{{.User}}", "{{.Password}}", 1, $null) | Out-Null
$t = $f.GetTask("\$name")
$t.Run($null) | Out-Null
$timeout = 10
$sec = 0
while ((!($t.state -eq 4)) -and ($sec -lt $timeout)) {
Start-Sleep -s 1
$sec++
}
function SlurpOutput($l) {
if (Test-Path $log) {
Get-Content $log | select -skip $l | ForEach {
$l += 1
Write-Host "$_"
}
}
return $l
}
$line = 0
do {
Start-Sleep -m 100
$line = SlurpOutput $line
} while (!($t.state -eq 3))
$result = $t.LastTaskResult
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($s) | Out-Null
exit $result`
))
provisioner/powershell/powershell.go
0 → 100644
View file @
040ff070
package
powershell
import
(
"encoding/base64"
)
func
powershellEncode
(
buffer
[]
byte
)
string
{
// 2 byte chars to make PowerShell happy
wideCmd
:=
""
for
_
,
b
:=
range
buffer
{
wideCmd
+=
string
(
b
)
+
"
\x00
"
}
// Base64 encode the command
input
:=
[]
uint8
(
wideCmd
)
return
base64
.
StdEncoding
.
EncodeToString
(
input
)
}
provisioner/powershell/provisioner.go
0 → 100644
View file @
040ff070
This diff is collapsed.
Click to expand it.
provisioner/powershell/provisioner_test.go
0 → 100644
View file @
040ff070
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment