Created
September 4, 2015 07:11
-
-
Save marshyski/3a3f37f15cd5cc7985a8 to your computer and use it in GitHub Desktop.
Windows fact to parse file by pattern and show field by space delimiter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Facter.Add(:test1) do | |
confine :kernel => 'Windows' | |
setcode do | |
powershell = 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' | |
test1 = 'Get-Content C:\test.txt | Select-String -Pattern "test1" - SimpleMatch | foreach { $_.ToString().split(" ")[1]}' | |
Facter::Util::Resolution.exec(%Q{#{powershell} -command "#{test1}"}) | |
end | |
end | |
# Below is example of file | |
# Content of C:\test.txt | |
# test1 one | |
# test2 two | |
# test3 three |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment