none
CSV mit drei "Spalten" in Variabel RRS feed

  • Frage

  • Guten Tag,

    ich habe folgendes Anliegen:

    Ich möchte ein CSV Datei die drei Komponenten enthält, in eine Variabel Importieren. Aus dieser möchte ich die einzelnen "Zellen" nehmen und in meinem Programm weiterverwenden.

    Hier mein Beispiel Code für das Importieren der CSV Datei:

    #CSV-File Checker
    $TestPath = Test-Path -Path $env:USERPROFILE\Documents\VDI-Programs-to-Check.csv
    
    if ($TestPath -eq $true) {
        $programs = Import-CSV -Path $env:USERPROFILE\Documents\VDI-Programs-to-Check.csv -Delimiter ";"
        Write-Host "VDI-Programs-to-Check.csv found!" -ForegroundColor Green
    }
    else {
        Write-Host "VDI-Programs-to-Check.csv not found!" -ForegroundColor Red
        Write-Host "Trying to Create CSV File to: $env:USERPROFILE\Documents ..." -ForegroundColor Green
        try {
            New-Item -Path $env:USERPROFILE\Documents\VDI-Programs-to-Check.csv -type "file" -value "#CSV for checking and installing Programs" | Out-Null
            Add-Content -Path $env:USERPROFILE\Documents\VDI-Programs-to-Check.csv -Value "`n#You can Edit this file in 'Microsoft Excel'"
            Add-Content -Path $env:USERPROFILE\Documents\VDI-Programs-to-Check.csv -Value "Program;InstallPath;SetupPath"
            Write-Host "VDI-Programs-to-Check.csv Successful created!" -ForegroundColor Green
        }
        catch {
            Write-Host "File could not be created!" -ForegroundColor Red
        }
    }

    Und hier der Beispiel Code für das Weiter-Verwenden der Variabel:

    for ($i = 0; $i -lt $programs.count; $i++) {
    
    try {
        $bool = Test-Path -Path "$programs[$i].InstallPath" -PathType container
        if($bool -eq $false)
        {
            Write-Host $programs[$i].Program " is not installed yet." -ForegroundColor Red
            Write-Host "`nStarting installtion..."
            try {
                Start-Process -FilePath "$programs[$i].SetupPath" -ArgumentList "/S /v/qn" -Verb runAs -Wait
                Write-Host "`nInstallation complete" -ForegroundColor Green
            }
            catch {
                Write-Host "`nSETUP NOT FOUND" -ForegroundColor Red
            }
            
            } else {
                Write-Host
                Write-Host $programs[$i].Program " is allready installed." -ForegroundColor Green
        }
    }
    catch {
        Write-Host "`nFAILD INSTALLATION" -ForegroundColor Red
    }
    }

    Und hier noch eine CSV Datei, die ich bisher verwendet habe (einwenig zensiert ;) ):

    #CSV for checking and installing Programs
    #You can Edit this file in 'Microsoft Excel'
    Program;InstallPath;SetupPath
    Enpass;C:\Program Files (x86)\Enpass;D:\Programme\Enpass\Enpass-setup.exe
    Fiddler;D:\Programme\Fiddler;\\SERVER\ORDNER\ORDNER\FiddlerSetup.exe
    Wireshark;C:\Program Files\Wireshark;\\SERVER\ORDNER\ORDNER\Wireshark\Wireshark-win64-1.12.7.exe
    VMware-Plugin;C:\Program Files (x86)\VMware\Enhanced Authentication Plug-in 6.7\;\\SERVER\ORDNER\ORDNER\VMware-6.7.0.exe
    

    Habt ihr eine Ahnung, wie man meine Idee richtig umsetzten kann?

    Vielen Dank!

    Freitag, 31. Mai 2019 12:23

Antworten