Discussion:
[vagrant-up] vagrant powershell elevated
Ozan Cansel
2018-11-14 13:04:39 UTC
Permalink
Hello, I want to run my powershell script dynamically with elevated
privileges. For example, on the host, I want to run vagrant powershell -c
"any command here". I know it can be done with provisioning with elevated
privilege but I need to run it on after 10 minutes from machine is up. Is
it possible ? I searched, googled but I could not found. On winrm-plugin
documents supports it with vagrant winrm -c -e "<cmd>" but when I installed
that plugin vagrant suggests to uninstall it. Could you help me about it ?
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/4227b10b-3ebf-49f4-b188-88bb2b9567cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alvaro Miranda Aguilera
2018-11-15 20:42:20 UTC
Permalink
hello

vagrant ssh

or
vagrant powershell will open a session as the vagrant user

or run a command with -c

you will have a way to run the command as admin

in linux . vagrant ssh -c 'sudo <sommand>' does the trick

in windows I am familiar only with `runas` but not sure whats the proper
powershell way.


vagrant will use the vagrant user

alvaro.
Post by Ozan Cansel
Hello, I want to run my powershell script dynamically with elevated
privileges. For example, on the host, I want to run vagrant powershell -c
"any command here". I know it can be done with provisioning with elevated
privilege but I need to run it on after 10 minutes from machine is up. Is
it possible ? I searched, googled but I could not found. On winrm-plugin
documents supports it with vagrant winrm -c -e "<cmd>" but when I installed
that plugin vagrant suggests to uninstall it. Could you help me about it ?
--
This mailing list is governed under the HashiCorp Community Guidelines -
https://www.hashicorp.com/community-guidelines.html. Behavior in
violation of those guidelines may result in your removal from this mailing
list.
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/vagrant-up/4227b10b-3ebf-49f4-b188-88bb2b9567cd%40googlegroups.com
<https://groups.google.com/d/msgid/vagrant-up/4227b10b-3ebf-49f4-b188-88bb2b9567cd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
Alvaro
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0eySEXipvDbU5e-ihr5nf38ZXTbqucpCYP_1_RsFnsPFAw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Ozan Cansel
2018-11-16 05:34:09 UTC
Permalink
My all guests are Windows. In powershell, I can invoke commands but
Start-Process destroys after closing session [it is normal]. Invoke-Wmi or
Diagnostics.Process::Start runs a process detached but there is a problem
also. 'vagrant powershell -c "<cmd>"' doesn't run as elevated or privileged
so my process doesn't run as elevated.

At last, I achieved but in a ugly way. I am writing my solution which might
help someone who suffered from the same problem.

When I want to run a script as elevated,
I insert the snippet to beginning of the VagrantFile, after I provision
the guest with '--provision-with <myscriptname>' option. After
provisioning I revert my file.

Before run :

Vagrant.configure(2) do |config|
config.vm.box = "win10_1607"
config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm",
auto_correct: true
config.winrm.guest_port = 5985
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
config.vm.network "private_network", ip: "192.168.50.11"
end

On running, I am adding my script :

$runElevatedScript = <<-SCRIPT
$start = new-object System.Diagnostics.ProcessStartInfo
$start.FileName = "some.exe"
$start.Arguments = "--silent"
$start.Verb = "runas"
[Diagnostics.Process]::Start($start)
SCRIPT

Vagrant.configure(2) do |config|
config.vm.box = "win10_1607"
config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm",
auto_correct: true
config.winrm.guest_port = 5985
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
#Provision here
config.vm.provision "myscriptname", type: "shell", inline:
$runElevatedScript
end

I provision at here with 'vagrant provision --provision-with myscriptname'

After I revert my VagrantFile

Vagrant.configure(2) do |config|
config.vm.box = "win10_1607"
config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm",
auto_correct: true
config.winrm.guest_port = 5985
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
config.vm.network "private_network", ip: "192.168.50.11"
end




15 Kasım 2018 Perşembe 23:42:37 UTC+3 tarihinde Alvaro Miranda Aguilera
Post by Alvaro Miranda Aguilera
hello
vagrant ssh
or
vagrant powershell will open a session as the vagrant user
or run a command with -c
you will have a way to run the command as admin
in linux . vagrant ssh -c 'sudo <sommand>' does the trick
in windows I am familiar only with `runas` but not sure whats the proper
powershell way.
vagrant will use the vagrant user
alvaro.
Post by Ozan Cansel
Hello, I want to run my powershell script dynamically with elevated
privileges. For example, on the host, I want to run vagrant powershell -c
"any command here". I know it can be done with provisioning with elevated
privilege but I need to run it on after 10 minutes from machine is up. Is
it possible ? I searched, googled but I could not found. On winrm-plugin
documents supports it with vagrant winrm -c -e "<cmd>" but when I installed
that plugin vagrant suggests to uninstall it. Could you help me about it ?
--
This mailing list is governed under the HashiCorp Community Guidelines -
https://www.hashicorp.com/community-guidelines.html. Behavior in
violation of those guidelines may result in your removal from this mailing
list.
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/vagrant-up/4227b10b-3ebf-49f4-b188-88bb2b9567cd%40googlegroups.com
<https://groups.google.com/d/msgid/vagrant-up/4227b10b-3ebf-49f4-b188-88bb2b9567cd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
Alvaro
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/1c6ccf70-1454-47f1-971e-57693581ceff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...