$webResults = Invoke-WebRequest -Uri 'https://reddit.com/r/powershell.json'
$rawJson = $webResults.Content
$objData = $rawJson | ConvertFrom-Json
$posts = $objData.data.children.data
$posts | Select-Object Title, Score | Sort-Object Score -Descending
load json data from website, convert to powershell object, sort
PS C:\Users\bob\ps> $logContent = Get-Content C:\Windows\Logs\CBS\CBS.log
>> $logContent | Select-String -Pattern "error"
2020-07-23 07:52:34, Info CBS Exec: Failed to read AutoRepairNeeded. [HRESULT =
0x80070490 - ERROR_NOT_FOUND]
2020-08-02 07:07:54, Info CBS Appl: Package:
Microsoft-Windows-IIS-WebServer-Package~31bf3856ad364e35~amd64~~10.0.18362.815, Update: IIS-HttpErrors,
Applicable: Applicable, Disposition: Installed
PS C:\Users\bob\ps> $logContent = Get-Content C:\Windows\Logs\CBS\CBS.log
>> $regex = "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"
>> $logContent | Select-String -Pattern $regex -AllMatches
#select string with ip address
2020-07-17 06:19:03, Info CBS Appl: detect Parent, Package:
Package_for_KB3064238~31bf3856ad364e35~amd64~~10.0.1.2, Parent:
Microsoft-Windows-Presentation-Package~31bf3856ad364e35~amd64~~10.0.10074.0, Disposition = Detect,
VersionComp: EQ, BuildComp: EQ, RevisionComp: GE, Exist: present
2020-07-17 06:19:03, Info CBS Appl: detect Parent, Package:
Package_for_KB3064238~31bf3856ad364e35~amd64~~10.0.1.2, Parent:
Microsoft-Windows-Presentation-Package~31bf3856ad364e35~amd64~~10.0.10115.0, Disposition = Detect,
VersionComp: EQ, BuildComp: EQ, RevisionComp: GE, Exist: present
PS C:\Users\bob\ps> $logContent = Get-Content C:\Windows\Logs\CBS\CBS.log
$logContent = $logContent | Select-String -Pattern 'error'
$logContent | Where-Object {$_ -like "*.*.*.*"}
2020-08-02 07:07:54, Info CBS Appl: Package:
Microsoft-Windows-IIS-WebServer-Package~31bf3856ad364e35~amd64~~10.0.18362.815, Update: IIS-HttpErrors,
Applicable: Applicable, Disposition: Installed
2020-08-02 07:07:54, Info CBS Appl: DetectUpdate, Package:
Microsoft-Windows-IIS-WebServer-ServerCommon-Package~31bf3856ad364e35~amd64~~10.0.18362.815, Remote
Parent: IIS-HttpErrors, Intended State: Installed
$rawCSVInput = Get-Content C:\Test\tt.csv
$objData = $rawCSVInput | ConvertFrom-Csv
$process = Get-Process
$process | Out-File -Path c:\Test\processInfo.txt
$process | ConvertTo-Csv -NoTypeInformation | Out-File c:\test\processes.csv
referemce:
https://www.youtube.com/watch?v=nnTlsNA3hPk
No comments:
Post a Comment