【问题标题】:Importing and exporting from CSV从 CSV 导入和导出
【发布时间】:2022-06-17 23:04:17
【问题描述】:

在这里,我正在尝试创建一个可以读取和写入 CSV 文件的程序。谁能看到我可能出错的地方?在 PowerShell 中运行。

$run = $true

$dataBase = "$PSScriptRoot\Vet.csv"


while ($run -eq $true)
{
    Write-Output "1. Add Patient"

    if ($choice -eq '1')
    {
        $name = Read-Host 'Enter the patient''s name'
        $bd = Read-Host "Enter the patient's birthdate (00/00/0000)"
        $gender = Read-Host "Male(m)/Female(f)"

        (Import-Csv -Path $dataBase -Encoding Default | ForEach-Object{ 
            if($name -eq '') 
            {
                $patient = New-Object PSObject -property @{
                    Name = $name
                    Birthdate = $bd
                    Gender = $gender
                }
            }
        } | ConvertTo-Csv -NoTypeInformation) -replace '"' | Out-File $dataBase
        
    }
    else
    {
        Write-Output "Please enter a valid input"
    }

}

【问题讨论】:

  • 如果您告诉我们运行脚本时实际发生的情况(包括您可能收到的任何错误消息),这会容易得多:)

标签: .net powershell csv


猜你喜欢
  • 1970-01-01
  • 2018-10-03
  • 1970-01-01
  • 2011-03-19
  • 2016-04-24
  • 2015-05-23
  • 2013-03-18
  • 2018-12-01
  • 1970-01-01
相关资源
最近更新 更多