hacktrist
Goto Top

Power Shell: Tagesordner anlegen

Hallo Power Shell Profis,

ich möchte das ein Script im Ordner C:\Test\ einen Ordner mit Unterordner anlegt der das aktuelle Datum in folgendem Format trägt.

C:\Test\20210520\xml\

Als nächstes möchte ich noch, dass alle xml Datein aus dem Ordner C:\Test in den Ordner C:\Test\20210520\xml verschoben werden.

Kann mir einer helfen?

Gruß
Tristan

Content-Key: 666905

Url: https://administrator.de/contentid/666905

Printed on: April 28, 2024 at 18:04 o'clock

Member: Doskias
Doskias May 20, 2021 at 05:55:25 (UTC)
Goto Top
Moin,

wie weit bist du denn?

Aktuelles Datum im gewünschten Format bekommst du ja mit
get-date -Format yyyyMMdd

Verschieben geht mit
move-item -Path c:\test\*.xml C:\Test\20210520\xml\

Beides keine große Sache. Wo hakt es?

Gruß
Doskias
Member: em-pie
Solution em-pie May 20, 2021 updated at 06:00:21 (UTC)
Goto Top
Moin,

$date = (Get-Date).toString("yyyyMMdd")  
Move-Item  -Path c:\tmp\*.xml C:\tmp\$date\xml

Geht bestimmt auch als One-Liner!?

Gruß
em-pie


Edit:
https://devblogs.microsoft.com/scripting/formatting-date-strings-with-po ...
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell. ...
Member: Hacktrist
Hacktrist May 20, 2021 at 05:59:11 (UTC)
Goto Top
Ich bin ganz neu in Powershell und es hakt bei beiden.
Ich hoffe das mir jemand in der Administrator.de Gemeinde das Script zur Verfügung stellt.

Ich möchte nicht dreist erscheinen, habe nur wirklich keine Ahnung wie es umgesetzt wird.

Gruß
Tristan
Member: Hacktrist
Hacktrist May 20, 2021 updated at 06:05:58 (UTC)
Goto Top
Hi @em-pie

das funktioniert noch nicht ganz, weil ich ja noch keinen Ordner mit dem Datum angelegt habe, somit klappt das verschieben nicht.

Move-Item  -Path C:\Arbeitsordner\Testordner\*.xml C:\Arbeitsordner\Testordner\$date\xml
Move-Item : Ein Teil des Pfads konnte nicht gefunden werden.
Member: Doskias
Solution Doskias May 20, 2021 updated at 06:07:34 (UTC)
Goto Top
Versuch mal em-pie erweitert:

$date = (Get-Date).toString("yyyyMMdd")  
new-Item -Path C:\tmp\$date\xml -ItemType directory
Move-Item  -Path c:\tmp\*.xml C:\tmp\$date\xml 

Gruß
Doskias
Member: Hacktrist
Hacktrist May 20, 2021 at 06:11:44 (UTC)
Goto Top
Dankeschön
Funktioniert perfekt
Mitglied: 148121
Solution 148121 May 20, 2021 updated at 09:46:49 (UTC)
Goto Top
Zitat von @em-pie:
Geht bestimmt auch als One-Liner!?
Absolut, wenns muss
md "C:\tmp\$(get-date -f yyyyMMdd)\xml" -Force | %{move-item "C:\tmp\*.xml" -Destination $_.FullName}  
Gruß w.