-
Notifications
You must be signed in to change notification settings - Fork 334
Remove use of wmic #1981
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
base: master
Are you sure you want to change the base?
Remove use of wmic #1981
Changes from all commits
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 |
|---|---|---|
|
|
@@ -2,10 +2,13 @@ module PSWindows::Group | |
| include Beaker::CommandFactory | ||
|
|
||
| def group_list | ||
| execute('cmd /c echo "" | wmic group where localaccount="true" get name /format:value') do |result| | ||
| execute('powershell.exe -NoProfile -NonInteractive -Command "Get-CimInstance Win32_Group -Filter \'LocalAccount=True\' | Select-Object -ExpandProperty Name"') do |result| | ||
| groups = [] | ||
| result.stdout.each_line do |line| | ||
| groups << (line.match(/^Name=(.+)$/) or next)[1] | ||
| group = line.strip | ||
| next if group.empty? | ||
|
|
||
| groups << group | ||
| end | ||
|
Comment on lines
6
to
12
Member
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. How about: groups = result.stdout.lines.map(&:strip).reject(&:empty?)This is also a repeated pattern in other files we can use to simplify the parsing. |
||
|
|
||
| yield result if block_given? | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,26 +24,16 @@ def path | |
| end | ||
|
|
||
| def get_ip | ||
| # when querying for an IP this way the return value can be formatted like: | ||
| # IPAddress= | ||
| # IPAddress={"129.168.0.1"} | ||
| # IPAddress={"192.168.0.1","2001:db8:aaaa:bbbb:cccc:dddd:eeee:0001"} | ||
| ips = execute('powershell.exe -NoProfile -NonInteractive -Command "(Get-CimInstance Win32_NetworkAdapterConfiguration -Filter \'IPEnabled=True\' | ForEach-Object { $_.IPAddress })"') | ||
|
Member
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. My understanding of the exec implementation is that it's the non-PowerShell implementation so can we really count on |
||
|
|
||
| ips = execute("wmic nicconfig where ipenabled=true GET IPAddress /format:list") | ||
|
|
||
| ip = '' | ||
| ips.each_line do |line| | ||
| matches = line.split('=') | ||
| next if matches.length <= 1 | ||
|
|
||
| matches = matches[1].match(/^{"(.*?)"/) | ||
| next if matches.nil? || matches.captures.nil? || matches.captures.empty? | ||
| ip = line.strip | ||
| next unless ip.match?(/^\d{1,3}(?:\.\d{1,3}){3}$/) | ||
|
|
||
| ip = matches.captures[0] if matches && matches.captures | ||
| break if ip != '' | ||
| return ip | ||
| end | ||
|
|
||
| ip | ||
| '' | ||
| end | ||
|
|
||
| # Attempt to ping the provided target hostname | ||
|
|
||
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.
Thoughts about: