• EnglishSpanishGermanFrenchPolishChinese (Traditional)


EnglishSpanishGermanFrenchPolishChinese (Traditional)

Operating systems, scripting, PowerShell and security

Operating systems, software development, scripting, PowerShell tips, network and security

Menú principal
  • Categorías
  • Cursos
  • Libro de PowerShell
  • Lo mejor
  • Lo último
  • Proyectos
  • Contactar
Ir al contenido

Ejercicios de PowerShell: ejercicios sobre ficheros

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#Listado donde fecha menor que dos días
ls D:\power\ejeclase | select Name,CreationTime | where CreationTime -LT (Get-Date).AddDays(-2)
 
#Mostrar según listado menor un día última fecha de escritura del fichero
Get-ChildItem | Where-Object {
$_.LastWriteTime -ge (Get-Date).AddDays(-1)
}
 
#Comparar contenido de dos ficheros
Compare-Object -ReferenceObject $(Get-Content F:\fichero1.txt) -DifferenceObject $(Get-Content F:\fichero2.txt)
 
#Get-ChildItem
Get-ChildItem -Path $home | select *
Get-ChildItem -Path $home | Get-Member
Get-ChildItem D:\power -Directory
 
#Comprimir y descomprimir
Compress-Archive -LiteralPath C:\powershell\example.txt -CompressionLevel Optimal -DestinationPath C:\powershell\comprimido.zip
Expand-Archive -LiteralPath C:\powershell\comprimido.zip -DestinationPath C:\powershell\descomprimir
Compress-Archive -LiteralPath C:\powershell\example2.txt -Update -DestinationPath C:\powershell\comprimido.zip
 
#Comprobar si existe o no un fichero
Test-Path c:\scripts\test.txt
 
#Listar ficheros según criterio de días
Get-Childitem F:\power\files | ? {$_.LastAccessTime -le (get-date).adddays(-1) -and $_.LastAccessTime -ge (get-date).adddays(-2) } | % {copy $_.Fullname c:\backup}

Publicado el día 9 de febrero de 2021

CATEGORÍAS

PowerShell, Sistema de archivos

ETIQUETAS

AddDays, Compare-Object, Compress-Archive, CompressionLevel, Copy, Date, Directory, Ejercicios de PowerShell, expand, Expand-Archive, Fullname, Get-ChildItem, Get-Content, Get-Date, Get-Member, Jesús Niño, Jesús Niño Camazón, ls, Optimal, Path, Where-Object

MÁS

  • 11. Gestión del Directorio Activo (nivel intermedio)
  • Ejercicios de PowerShell: mostrar los ficheros que se han modificado de ayer a hoy
  • Gestión de la información (Sistemas informáticos)
  • Ejercicios de seguridad: práctica sobre virus
  • Ejercicios de PowerShell: trabajar con fechas (listar varios días)
  • Obtener los nombres de las funciones exportadas de un archivo DLL con DUMPBIN desde PowerShell (explicación paso a paso del script)