-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed usages from powershell commands #1
Changes from all commits
4074ad4
a8414d0
1dbe0cf
5a77b14
f2bee8a
931a5ec
6282456
e89d83b
a497291
5b76be3
fe3c394
1b02c5f
077e0cc
014da6c
f18e3f5
79fa39b
4fa547c
9cc57e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,6 @@ var HypervBox = { | |
return 'powershell.exe'; | ||
}, | ||
// TODO: ..We'll probably need a differnt command here in the future. That's why code dupe. | ||
commandElevated: function () { | ||
return 'powershell.exe'; | ||
}, | ||
installed: function () { | ||
return util.execFile([this.command(), '@(Get-Command get-vm).ModuleName']).then(stdout => { | ||
console.log('stdout: ', stdout); | ||
|
@@ -31,37 +28,40 @@ var HypervBox = { | |
*/ | ||
|
||
hasAdminRights: function() { | ||
return util.execFile([this.command(), 'Get-VMHostSupportedVersion']).then(stdout => { | ||
return util.execFile([this.command(), 'Get-VMHost']).then(stdout => { | ||
console.log('stdout: ', stdout); | ||
// To execute the above command you'll need Admin or Hyper-V-Admin rights. | ||
if ( stdout.toUpperCase().indexOf('TRUE') !== -1) { | ||
if (stdout.toLowerCase().indexOf('fullyqualifiederrorid') === -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you have a problem with this admin test command? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That function is not available for all installations. It is present on 50% of the machines I've tested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah. ok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't pinpointed which package/program added the powershell commands :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just found
As you suggested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the above lines of code. |
||
return Promise.resolve(true); | ||
} | ||
return Promise.resolve(false); | ||
}).catch(() => { | ||
return Promise.resolve(false); | ||
}); | ||
}, | ||
switchName: function (name) { | ||
// return util.execFile([this.command(), '$(Get-VMSwitch | where {$_.SwitchType -eq "external"}).name']).then(out => { | ||
return util.execFile([this.command(), '$(Get-VMSwitch).name']).then(out => { | ||
// We use the same mechanism as docker-machine. Use the first switch we find. | ||
return (out.replace('\r','').split('\n')[0]); | ||
var name = (out.replace('\r','').split('\n')[0]); | ||
if (name !== null && name !== '') | ||
return name; | ||
else | ||
return false; | ||
}).catch(() => { | ||
return false; | ||
}); | ||
}, | ||
version: function () { | ||
version: function (machineName) { | ||
// there seems to be a problem with elevated execution. see: https://github.com/nodejs/node-v0.x-archive/issues/6797 | ||
// The only easy possibility seems to be to communicat with a file. | ||
|
||
return util.execFile([this.command(), 'Get-VMHostSupportedVersion']).then(stdout => { | ||
|
||
let match = stdout.match(/^(.*) True/im); | ||
if (match != null) { | ||
return util.execFile([this.command(), 'Get-VM | Where {$_.Name -eq "'+ machineName +'" -and $_.Version} | select Version']).then(stdout => { | ||
let match = stdout.match(/\d+(?:\.\d+)+/g); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did test the stuff. Seems to work with hyper-v, but there is a problem here. needs to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (match != null && match.length >= 1) { | ||
// matched text: match[0] | ||
// match start: match.index | ||
// capturing group n: match[n] | ||
return Promise.resolve(match[1]); | ||
return Promise.resolve(match[0]); | ||
} | ||
Promise.reject('No VM version information found'); | ||
}).catch(() => { | ||
|
@@ -76,8 +76,9 @@ var HypervBox = { | |
// Needed for consistency check | ||
vmExists: function (name) { | ||
return util.execFile([this.command(), "Get-VM | Where {$_.Name -eq '" + name + "'}"]).then(out => { | ||
console.log(out) | ||
return (out.indexOf(name) !== -1); | ||
console.log(out); | ||
var machineExists = out.indexOf(name) !== -1; | ||
return machineExists; | ||
}).catch(() => { | ||
return false; | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import util from './Util'; | ||
|
||
var PowershellUtil = | ||
{ | ||
runCommandWithArgs : function (args) { | ||
console.log("cmd: ", args); | ||
return util.execFile([this.commandElevated(), 'start-process', 'powershell', '-verb', 'runas', '-wait', '-argumentList', args]).then(stdout => { | ||
return Promise.resolve(null); | ||
}).catch((error) => { | ||
throw new Error(error.message); | ||
}); | ||
}, | ||
commandElevated: function commandElevated() { | ||
return 'powershell.exe'; | ||
}, | ||
}; | ||
|
||
module.exports = PowershellUtil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I run the command
get-vmhost
from a non elevated powershell I get this output:So for me there is no text "invalidoperation" ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, so maybe FullyQualifiedErrorId would be better to check for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmario changed this in my latest commit.