Share via

script powershell

jorge rosales 1 Reputation point
2021-02-10T20:33:11.367+00:00

Buena tarde, tengo el siguiente scrip de power shell

Get-ChildItem \servidor\c$\carpeta\LOGS\$FECHA -Name | select -Last 1 | Get-Content -Wait -Tail 10

el problema que tengo es que el nombre del archivo cambia cada hora , el script anterior al cambiar de hora no se sigue ejecutando si no que se detiene como puedo hacer para que al cambiar de hora el scrip siga obteniendo el ultimo archivo y seguir leyendo su contenido

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Rich Matheisen 48,116 Reputation points
    2021-02-10T21:17:39.873+00:00

    How about something like this?

    Get-ChildItem \\servidor\c$\carpeta\LOGS\*.* -File |
        Sort-Object CreationTime -Descending |
            Select-Object Name -Last 1
    

    But you're also using the -Wait parameter on the Get-Content. How are you going to end this execution, or close the file (short of deleting it), so you can start reading the new file???

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.