I am using powershell to get the contents of a log file. I am trying to extract an unknown string between two known words. I need to do this for multiple lines so i want multiple strings searched and returned. I have seen many examples and tried different ways but they dont work.
I have used reg ex to narrow it down to the lines in the log i care about, but i am unable to extract the text i want.
$fails = Select-String -Path 'C:\Users\user\Documents\wsyncmgr.log' -Pattern "^(?=.*?\bError\b)(?=.*?\bSoftware\b)(?=.*?\bLicense\b)(?=.*?\bTerms\b)(?=.*?\bnot\b)(?=.*?\bdownloaded\b).*$"
this returns:
C:\Users\user\Documents\wsyncmgr.log:7340:Failed to sync update 817ad2a6-3ca7-4fa2-aa32-9b906a2d9fdc. Error: The Microsoft Software License Terms have not been completely
downloaded and~~cannot be accepted. Source: Microsoft.UpdateServices.Internal.BaseApi.SoapExceptionProcessor.DeserializeAndThrow $$<SMS_WSUS_SYNC_MANAGER><10-23-2019
08:31:07.642+300><thread=5916 (0x171C)>
C:\Users\user\Documents\wsyncmgr.log:7341:Failed to sync update 87e13ecb-c669-43be-9e2a-01e567285031. Error: The Microsoft Software License Terms have not been completely
downloaded and~~cannot be accepted. Source: Microsoft.UpdateServices.Internal.BaseApi.SoapExceptionProcessor.DeserializeAndThrow $$<SMS_WSUS_SYNC_MANAGER><10-23-2019
08:31:07.643+300><thread=5916 (0x171C)>
etc..
i just want to extract update unique id so i can put them all into a variable and use later.
Closest i have got is
$removeFirst = $fails -split "update "
$removeLast = $removeFirst -split ". Error:"
$removeLast[1]
C:\Users\user\Documents\wsyncmgr.log:7341:Failed to sync
87e13ecb-c669-43be-9e2a-01e567285031
The Microsoft Software License Terms have not been completely downloaded and~~cannot be accepted. Source: Microsoft.UpdateServices.Internal.BaseApi.SoapExceptionProcessor.DeserializeAndThrow $$<SMS_WSUS_SYNC_MANAGER><10-23-2019 08:31:07.643+300><thread=5916 (0x171C)>
C:\Users\user\Documents\wsyncmgr.log:7342:Failed to sync
c1a1ec21-8efc-4cd4-8e85-90a03fc7b0c8
The Microsoft Software License Terms have not been completely downloaded and~~cannot be accepted. Source: Microsoft.UpdateServices.Internal.BaseApi.SoapExceptionProcessor.DeserializeAndThrow $$<SMS_WSUS_SYNC_MANAGER><10-23-2019 08:31:07.644+300><thread=5916 (0x171C)>
C:\Users\user\Documents\wsyncmgr.log:7343:Failed to sync
09dc7113-fa44-4ca8-9d70-ec254d4d2f04
The Microsoft Software License Terms have not been completely downloaded and~~cannot be accepted. Source: Microsoft.UpdateServices.Internal.BaseApi.SoapExceptionProcessor.DeserializeAndThrow $$<SMS_WSUS_SYNC_MANAGER><10-23-2019 08:31:07.644+300><thread=5916 (0x171C)>
but that only removes the words i specify and puts the rest on a separate line. then the array only returns the line i specify but i want multiple. I want to eliminate everything before "update " and everything after ". Error:" leaving only "09dc7113-fa44-4ca8-9d70-ec254d4d2f04" for each line.
any help would be appreciated im no good with regex