PowerShell Training · Topic 20

Generar un paquete final listo para BI o carga a sistema

Un ejercicio práctico para entregar data limpia, archivos procesados, excluidos y reporte de auditoría en una carpeta final.

Generate a final package ready for bi or system upload

A hands-on exercise to deliver clean data, processed files, excluded items, and an audit report in a final folder.

⚠️ Advertencia crítica antes de correr cualquier script

No ejecutes este tipo de script en un ambiente de producción, carpeta real, servidor compartido, unidad de red o sistema institucional sin autorización formal.

PowerShell es una herramienta poderosa: un comando de renombrado masivo puede modificar cientos o miles de archivos en segundos. En una carpeta equivocada, eso puede causar pérdida de trazabilidad, fallos en procesos automáticos, interrupciones operativas o incidentes de ciberseguridad.

Regla obligatoria del training: primero se trabaja con data sintética, luego se valida con una muestra pequeña, después se prueba con -WhatIf cuando aplique, y solo entonces se considera ejecutar en datos reales siguiendo los protocolos de la organización.

  • Permisos: usa solamente carpetas donde tengas autorización explícita.
  • Backups: confirma que exista copia de seguridad o posibilidad real de recuperación.
  • Cybersecurity: cumple las políticas internas, controles de acceso, change management y principios de menor privilegio.
  • Producción: nunca ejecutes scripts masivos directamente sobre producción sin revisión, aprobación y plan de reversa.

⚠️ Critical warning before running any script

Do not run this type of script in a production environment, real folder, shared server, network drive, or institutional system without formal authorization.

PowerShell is a powerful tool: a bulk command can modify hundreds or thousands of files in seconds. In the wrong folder, it can break traceability, disrupt automated processes, create operational issues, or trigger cybersecurity incidents.

Mandatory training rule: start with synthetic data, validate with a small sample, test with -WhatIf when applicable, and only then consider real data while following your organization’s protocols.

  • Permissions: use only folders where you have explicit authorization.
  • Backups: confirm that a backup or real recovery option exists.
  • Cybersecurity: follow internal policies, access controls, change management, and least-privilege principles.
  • Production: never run bulk scripts directly on production without review, approval, and rollback planning.

Objetivo del Topic 20

El objetivo es crear una carpeta final organizada con todos los entregables de un proceso: data limpia, reportes, archivos encontrados, excluidos y auditoría.

01 · Crear entregables
02 · Empaquetar final
03 · Verificar paquete
Idea central: La automatización crea confianza cuando termina en una entrega organizada y verificable.

Topic 20 Objective

The goal is to create an organized final folder with all process deliverables: clean data, reports, found files, excluded files, and audit evidence.

01 · Create deliverables
02 · Build final package
03 · Verify package
Core idea: Automation builds trust when it ends in an organized and verifiable delivery.

Ruta de trabajo

Todo se ejecuta dentro de una carpeta controlada:

Working folder

Everything runs inside a controlled folder:

$BasePath = "$env:USERPROFILE\Documents\AI Practical Training\PowerShell\Topic 20"

Qué vamos a aprender

  • Crear estructura final de entrega.
  • Copiar archivos limpios y reportes.
  • Separar found/excluded.
  • Generar manifest de entrega.
  • Preparar paquete para BI o sistema.

What you will learn

  • Create a final delivery structure.
  • Copy clean files and reports.
  • Separate found/excluded.
  • Generate a delivery manifest.
  • Prepare a package for BI or system upload.
01

Script 1 — Crear data sintética

Este script prepara los archivos o datos de práctica necesarios para ejecutar el ejercicio sin tocar información real.

Script 1 — Create synthetic data

This script prepares the practice files or data needed to run the exercise without touching real information.

# ======================================================
# Topic 20 - Script 1
# Create synthetic deliverables
# ======================================================

$BasePath = "$env:USERPROFILE\Documents\AI Practical Training\PowerShell\Topic 20"
$DataPath = Join-Path $BasePath "Data"
$ReportsPath = Join-Path $BasePath "Reports"
$FoundPath = Join-Path $BasePath "Found"
$ExcludedPath = Join-Path $BasePath "Excluded"
$FinalPath = Join-Path $BasePath "Final_Package"

New-Item -Path $DataPath, $ReportsPath, $FoundPath, $ExcludedPath, $FinalPath -ItemType Directory -Force | Out-Null

@(
    [PSCustomObject]@{ Employee_ID = "10001"; Name = "John Smith"; Status = "Clean" },
    [PSCustomObject]@{ Employee_ID = "10002"; Name = "Maria Garcia"; Status = "Clean" }
) | Export-Csv (Join-Path $DataPath "clean.csv") -NoTypeInformation

@(
    [PSCustomObject]@{ File_Name = "10001.jpg"; Result = "Processed" },
    [PSCustomObject]@{ File_Name = "99999.jpg"; Result = "Excluded" }
) | Export-Csv (Join-Path $ReportsPath "audit.csv") -NoTypeInformation

"Found photo" | Set-Content (Join-Path $FoundPath "10001.jpg")
"Excluded photo" | Set-Content (Join-Path $ExcludedPath "99999.jpg")

Write-Host "Synthetic deliverables created in:"
Write-Host $BasePath
02

Script 2 — Ejecutar la acción principal

Este script aplica la lógica central del topic y genera el resultado principal del ejercicio.

Script 2 — Run the main action

This script applies the core logic of the topic and generates the main result of the exercise.

# ======================================================
# Topic 20 - Script 2
# Generate final package
# ======================================================

$BasePath = "$env:USERPROFILE\Documents\AI Practical Training\PowerShell\Topic 20"
$FinalPath = Join-Path $BasePath "Final_Package"

$FinalDataPath = Join-Path $FinalPath "Data"
$FinalReportsPath = Join-Path $FinalPath "Reports"
$FinalFoundPath = Join-Path $FinalPath "Found"
$FinalExcludedPath = Join-Path $FinalPath "Excluded"

New-Item -Path $FinalDataPath, $FinalReportsPath, $FinalFoundPath, $FinalExcludedPath -ItemType Directory -Force | Out-Null

Copy-Item (Join-Path $BasePath "Data\clean.csv") $FinalDataPath -Force
Copy-Item (Join-Path $BasePath "Reports\audit.csv") $FinalReportsPath -Force
Copy-Item (Join-Path $BasePath "Found\*") $FinalFoundPath -Force
Copy-Item (Join-Path $BasePath "Excluded\*") $FinalExcludedPath -Force

$ManifestPath = Join-Path $FinalPath "Final_Package_Manifest.csv"

Get-ChildItem $FinalPath -Recurse -File |
Select-Object Name, FullName, Length, LastWriteTime |
Export-Csv $ManifestPath -NoTypeInformation

Write-Host "Final package created:"
Write-Host $FinalPath
Nota: revisa siempre el resultado en una carpeta de práctica antes de adaptar el patrón a datos reales.
Note: always review the result in a practice folder before adapting the pattern to real data.
03

Script 3 — Verificar o reportar resultados

Este script confirma el resultado final o genera evidencia para revisión.

Script 3 — Verify or report results

This script confirms the final result or generates evidence for review.

# ======================================================
# Topic 20 - Script 3
# Verify final package
# ======================================================

$BasePath = "$env:USERPROFILE\Documents\AI Practical Training\PowerShell\Topic 20"
$FinalPath = Join-Path $BasePath "Final_Package"
$ManifestPath = Join-Path $FinalPath "Final_Package_Manifest.csv"

Write-Host "Final package structure:"
Get-ChildItem $FinalPath -Recurse | Select-Object FullName

Write-Host ""
Write-Host "Manifest preview:"
Import-Csv $ManifestPath | Format-Table Name, Length, LastWriteTime -AutoSize

Explicación simple del script

  • New-Item crea la estructura final.
  • Copy-Item mueve copias de entregables al paquete final.
  • Los archivos originales permanecen en sus carpetas de trabajo.
  • El manifest documenta el contenido del paquete.
  • La verificación muestra la estructura final.

Simple script explanation

  • New-Item creates the final structure.
  • Copy-Item places copies of deliverables in the final package.
  • Original files remain in their work folders.
  • The manifest documents package contents.
  • Verification displays the final structure.

Ejemplo esperado

Entrada / CasoResultado
Data/clean.csvClean data
Reports/audit.csvAudit evidence
Found/10001.jpgProcessed file
Excluded/99999.jpgReview item

Expected example

Input / CaseResult
Data/clean.csvClean data
Reports/audit.csvAudit evidence
Found/10001.jpgProcessed file
Excluded/99999.jpgReview item

Conclusión

Este topic cierra la serie con una entrega profesional: no solo se procesan datos, se entrega un paquete claro, auditable y listo para BI o carga a sistema.

Lección clave: La automatización crea confianza cuando termina en una entrega organizada y verificable.

Conclusion

This topic closes the series with professional delivery: data is not only processed, it is delivered as a clear, auditable package ready for BI or system upload.

Key lesson: Automation builds trust when it ends in an organized and verifiable delivery.