0

Ansible: 2.9 PowerShell: 5 OS: w2k16 Server

Hi all!

I search the method to filter the stdout of Format-Hex from PowerShell launched by ansible.

code:

win_shell: |
 Format-Hex C:\test.txt
register: recorder


debug:
  msg: {{ recorder }}

I see:

            0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F

00000000   42 4D 5E 00 00 00 00 00 00 00 36 00 00 00 28 00  BM^.......6...(. 
00000010   00 00 0A 00 00 00 01 00 00 00 01 00 20 00 00 00  ............ ... 
00000020   00 00 00 00 00 00 C4 0E 00 00 C4 0E 00 00 00 00  ......Ä...Ä..... 
00000030   00 00 00 00 00 00 B7 59 71 FF B7 59 71 FF B7 59  ......•Yq.•Yq.•Y 
00000040   71 FF B7 59 71 FF B7 59 71 FF B7 59 71 FF B7 59  q.•Yq.•Yq.•Yq.•Y 
00000050   71 FF B7 59 71 FF B7 59 71 FF B7 59 71 FF        q.•Yq.•Yq.•Yq.

But I only desire:

the all lines contained Hexa data:

42 4D 5E 00 00 00 00 00 00 00 36 00 00 00 28 00
...
...

Thanks again!

0

1 Answer 1

1

Try this, It works for me:

PS /~> cat .\test.txt
            0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F

00000000   42 4D 5E 00 00 00 00 00 00 00 36 00 00 00 28 00  BM^.......6...(. 
00000010   00 00 0A 00 00 00 01 00 00 00 01 00 20 00 00 00  ............ ... 
00000020   00 00 00 00 00 00 C4 0E 00 00 C4 0E 00 00 00 00  ......Ä...Ä..... 
00000030   00 00 00 00 00 00 B7 59 71 FF B7 59 71 FF B7 59  ......•Yq.•Yq.•Y 
00000040   71 FF B7 59 71 FF B7 59 71 FF B7 59 71 FF B7 59  q.•Yq.•Yq.•Yq.•Y 
00000050   71 FF B7 59 71 FF B7 59 71 FF B7 59 71 FF        q.•Yq.•Yq.•Yq.

PS /~> cat .\test.txt|select -Skip 1|%{($_ -split '\s{2,}')[1]}
42 4D 5E 00 00 00 00 00 00 00 36 00 00 00 28 00
00 00 0A 00 00 00 01 00 00 00 01 00 20 00 00 00
00 00 00 00 00 00 C4 0E 00 00 C4 0E 00 00 00 00
00 00 00 00 00 00 B7 59 71 FF B7 59 71 FF B7 59
71 FF B7 59 71 FF B7 59 71 FF B7 59 71 FF B7 59
71 FF B7 59 71 FF B7 59 71 FF B7 59 71 FF

PS /~>
  • Skip first Line (Header)
  • For each line, split where there is 2 or more spaces which generates a 3 item array and we get the item on position 1 which is the output you're interested on.
  • Sign up to request clarification or add additional context in comments.

    Comments

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.