Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $switch = "";
- $pathtowrite = $env:USERPROFILE + "\Verzeichnisse"
- $csvfilepath
- $csvdata
- $counter = 0
- $textfortextfile
- function CreateFolderIfNotExists($path)
- {
- if((Test-Path $path) -eq 0)
- {
- New-Item -ItemType Directory -Force -Path $path
- }
- }
- function Deletedir()
- {
- $antwort = Read-Host "Wollen Sie wirklich " $pathtowrite " Recursive löschen? [J/N]"
- if($antwort -eq "J" -or $antwort -eq "j")
- {
- Remove-Item -Recurse -Force $pathtowrite
- Write-Host "Ordner Wurden gelöscht!"
- }
- else
- {
- Write-Host "Canceling...."
- }
- }
- function ReadCSVData($csvpath)
- {
- $csvdata = Import-Csv $csvfilepath -Delimiter "," -Encoding Default
- createDirForUsers($csvdata)
- }
- function createTextFileforUser($path)
- {
- New-Item -ItemType File -Force -Path ($path + "\Hinweis.txt")
- Set-Content -Value $textfortextfile -Path ($path + "\Hinweis.txt")
- }
- function createDirForUsers($csvdata)
- {
- $csvdata | ForEach-Object {
- $userpath = $pathtowrite+ "\" + $_.Langname + "_" + $_.Vorname.substring(0,2) + "_" + $_.Klasse
- New-Item -ItemType Directory -Force -Path $userpath
- $counter = $counter +1
- $textfortextfile = "Willkommen " + $_.Langname + " " + $_.Vorname
- #Write-Host $userpath
- createTextFileforUser($userpath)
- }
- Write-Host "------------------"
- Write-Host "Es wurden " + $counter + " Ordner erstellet!"
- }
- function getCSVPath()
- {
- $csvfilepath = Read-Host "Bitte geben Sie den Pfad oder Dateinamen der CSV datei an!"
- if((Test-Path $csvfilepath) -eq 0)
- {
- Write-Host "Kann die CSV datei nicht finden. Breche ab"
- }
- else
- {
- ReadCSVData($csvfilepath)
- }
- }
- if($args.Count -eq 0)
- {
- Write-Host "Sie haben keinen Switch angegeben. Es wird der default switch -Create verwendet"
- $switch = "Create"
- CreateFolderIfNotExists($pathtowrite)
- getCSVPath
- }
- elseif($args.Count -gt 1)
- {
- Write-Host "Bitte nur einen Parameter angeben"
- }
- elseif($args[0] -eq "-Create" -or $args[0] -eq "Create")
- {
- Write-Host "-Create switch wurde gewählt...."
- $switch = "Create"
- CreateFolderIfNotExists($pathtowrite)
- getCSVPath
- }
- elseif($args[0] -eq "-Delete" -or $args[0] -eq "Delete")
- {
- Write-Host "-Delete switch wurde gewählt...."
- $switch = "Delete"
- Deletedir
- }
- else
- {
- Write-Host "ERROR. Bitte überprüfen Sie Ihre eingabe"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement