我有一个 powershell 脚本,旨在读取远程服务器上的 txt 文件并将其导入 SQL 中。
我希望能够跳过 txt 文件的前两行。我目前正在使用下面的代码来导入文件。 txt 文件已分隔
$datatable = new-object System.Data.DataTable
$reader = New-Object System.IO.StreamReader($empFile)
$columns = (Get-Content $empfile -First 1).Split($empFileDelimiter)
if ($FirstRowColumnNames -eq $true)
{
$null = $reader.readLine()
}
foreach ($column in $columns)
{
$null = $datatable.Columns.Add()
}
# Read in the data, line by line, not column by column
while (($line = $reader.ReadLine()) -ne $null)
{
$null = $datatable.Rows.Add($line.Split($empFiledelimiter))
column 参数采用 txt 文件的第一行并为 PS 数据表创建列。
我遇到的问题是不需要 txt 文件的前两行,我需要跳过它们并使用 txt 文件的第三行作为列。我有以下代码行可以执行此操作,但我不确定如何将其集成到我的代码中。
get-content $empFile | select-object -skip 2
为$empfile
没有前两行,然后使用数组的第一项作为列,如下所示:
$Content = Get-Content $empFile | Select-Object -Skip 2
$columns = $Content[0].Split($empFileDelimiter)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)