@@ -3952,7 +3952,14 @@ def get_windows_nic_attribute(
39523952 :param target: which nic attribute you want to get.
39533953
39543954 """
3955- cmd = 'wmic %s where %s="%s" get %s' % (global_switch , key , value , target )
3955+ if utils_misc .is_wmic_available (session ):
3956+ cmd = 'wmic %s where %s="%s" get %s' % (global_switch , key , value , target )
3957+ else :
3958+ value_ps = value .replace (":" , "-" ).upper ()
3959+ cmd = (
3960+ "PowerShell -NoProfile -Command "
3961+ "\" (Get-NetAdapter | Where-Object {{$_.{key} -eq '{value}'}}).Name\" "
3962+ ).format (key = key , value = value_ps )
39563963 status , out = session .cmd_status_output (cmd , timeout = timeout )
39573964 if status != 0 :
39583965 err_msg = "Execute guest shell command('%s') " "failed with error: '%s'" % (
@@ -3961,8 +3968,9 @@ def get_windows_nic_attribute(
39613968 )
39623969 raise exceptions .TestError (err_msg )
39633970 lines = [l .strip () for l in out .splitlines () if l .strip ()]
3964- # First line is header, return second line
3965- return lines [1 ]
3971+ # WMIC output has a header (value is in lines[1])
3972+ # PowerShell output has no header, so return out.strip()
3973+ return lines [1 ] if len (lines ) > 1 else out .strip ()
39663974
39673975
39683976def set_win_guest_nic_status (session , connection_id , status , timeout = 240 ):
0 commit comments