apparentlysimon
Goto Top

Mit Powershell automatisiert Ordner erstellen

Hallo liebe Community,

ich möchte eine Ordnerstruktur anlegen. Im folgenden Folder möchte ich automatisiert Ordner anlegen.
Dafür habe ich mir ein Array gebastelt und ein Programm erstellt, welches das Array durchlaufen wird und für jede stelle im Array einen Ordner anlegt. Leider weiß ich aber nicht weiter und hoffe, dass jemand mir bei der Aufgabe helfen kann.

$computerlist = @("BCI-TH-PC01", "BCI-TH-PC02", "BCI-TH-PC03", "BCI-TH-PC04", "BCI-TH-PC05", "BCI-TH-PC06", "BCI-TH-PC07", "BCI-TH-PC08", "BCI-TH-PC09", "BCI-TH-PC10")

for($i = 0; $i -lt $computerlist.length; $i++){
##Erstelle für jede Stelle im Array einen Ordner (mit dem Namen BCI-TH-PC01, usw...) im folgenden Folder: "c:\TestPS".
}

Viele Grüße und danke für die Hilfe!
Simon

Content-ID: 2473103722

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

Ausgedruckt am: 28.09.2024 um 21:09 Uhr

1915348599
Lösung 1915348599 11.04.2022 aktualisiert um 11:44:58 Uhr
Goto Top
$computerlist = "BCI-TH-PC01", "BCI-TH-PC02", "BCI-TH-PC03", "BCI-TH-PC04", "BCI-TH-PC05", "BCI-TH-PC06", "BCI-TH-PC07", "BCI-TH-PC08", "BCI-TH-PC09", "BCI-TH-PC10"  
foreach($computer in $computerlist){
    md "C:\TestPS\$computer" -force  
}
about_Foreach
ApparentlySimon
ApparentlySimon 11.04.2022 um 11:47:28 Uhr
Goto Top
Danke dir! So funktioniert es wunderbar!
MrCount
MrCount 11.04.2022 um 11:52:14 Uhr
Goto Top
Wenn das zu deinem vorherigen Beitrag ist, dann kannst du das Script hiermit ergänzen:

...
$command = Invoke-Command ....

$path = "C:\TestPS\$computer"  

New-Item -ItemType Directory -Force -Path $path

$command | out-file "$path\SoftwareTest.txt " -append  
...