Focused on logs, XML (SII), CSV, automation, and system control.
# Help
Get-Help Select-String -Online
# Search for commands
Get-Command *csv*
ls # Get-ChildItem
cd # Set-Location
cat # Get-Content
rm # Remove-Item
cp # Copy-Item
mv # Move-Item
Set-Location "C:\Users\rfors\OneDrive\job\MM\JSM contabilidad"
Get-ChildItem
Get-ChildItem -Recurse
Get-ChildItem -Recurse -Filter *.xml
Copy-Item file.xml .\backup\
Move-Item *.log .\logs\
Remove-Item *.tmp -WhatIf
Get-ChildItem -Recurse -File |
Select-String -Pattern "34-AX25-001121" -SimpleMatch
Get-ChildItem -Recurse -File |
Select-String "34-AX25-001121" -SimpleMatch |
Select-Object -Unique Path
Get-ChildItem -Recurse -Filter *.xml |
Select-String "34-AX25-001121" -SimpleMatch
Get-Content .\sii_validator.log -Tail 100 -Wait |
Select-String "ERROR"
$xml = [xml](Get-Content "file.xml")
$xml.Envelope.Body.SuministroLRFacturasEmitidas.RegistroLRFacturasEmitidas |
ForEach-Object {
[PSCustomObject]@{
NumSerie = $_.IDFactura.NumSerieFacturaEmisor
Total = $_.FacturaExpedida.ImporteTotal
}
}
$xml.Envelope.Body.SuministroLRFacturasEmitidas.RegistroLRFacturasEmitidas |
Where-Object { -not $_.FacturaExpedida.ClaveRegimenEspecialOTrascendencia } |
Select-Object @{
N='Factura';E={$_.IDFactura.NumSerieFacturaEmisor}
}, @{
N='Importe';E={$_.FacturaExpedida.ImporteTotal}
}
$csv = Import-Csv "ventas.csv"
$csv | Where-Object { [decimal]$_.Total -gt 1000 }
$csv |
Group-Object Customer |
ForEach-Object {
[PSCustomObject]@{
Customer = $_.Name
Suma = ($_.Group | Measure-Object -Property Total -Sum).Sum
}
} |
Sort-Object Suma -Descending |
Export-Csv "resumen-clientes.csv" -NoTypeInformation
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
Restart-Service -Name "MyServiceName"
python script.py
kubectl get pods
git status
Get-ChildItem -Recurse -Filter *.xml |
Where-Object { $_.Length -gt 1MB } |
Select-Object FullName, Length
Get-ChildItem -Recurse -File |
Select-String "34-AX25-001121" -SimpleMatch
$xml... |
ForEach-Object {
[PSCustomObject]@{
Factura = $_.IDFactura.NumSerieFacturaEmisor
Total = $_.FacturaExpedida.ImporteTotal
}
}
Import-Csv "ventas.csv" |
Group-Object Customer |
ForEach-Object {
[PSCustomObject]@{
Customer = $_.Name
Total = ($_.Group | Measure-Object Amount -Sum).Sum
}
}
try {
$xml = [xml](Get-Content "file.xml" -ErrorAction Stop)
} catch {
Write-Warning $_.Exception.Message
}
$codes = @{ '10'='Telecom'; '01'='General' }
$codes['10']
$p = @{
Path="C:\SII"
Filter="*.xml"
Recurse=$true
}
Get-ChildItem @p
function Find-Invoice {
param($Root, $Invoice)
Get-ChildItem $Root -Recurse -File |
Select-String $Invoice -SimpleMatch
}
... | Export-Csv "out.csv" -NoTypeInformation
... | ConvertTo-Json | Out-File "out.json"
# nightly log check
Get-ChildItem "C:\SII" -Recurse -Filter *.log |
Select-String "error" |
Out-File "C:\SII\_reports\errors.log"