在Powershell脚本中转换PHP脚本

在Powershell脚本中转换PHP脚本,php,powershell,Php,Powershell,我必须在Powershell脚本中转换PHP脚本。 我有当前的PHP脚本: <?php // read text file $File = fopen("file.txt", "r") or die("Unable to open file!"); $typePers = array("Personale Viaggiante","Personale Interno"); $excludeFields = array("IT0006","IT0017","IT0077","Personal

我必须在Powershell脚本中转换PHP脚本。
我有当前的PHP脚本:

<?php
// read text file
$File = fopen("file.txt", "r") or die("Unable to open file!");
$typePers = array("Personale Viaggiante","Personale Interno");
$excludeFields = array("IT0006","IT0017","IT0077","Personale Viaggiante","Personale Interno","IT0105");
$emptyValue = "NaN";
$rowfinal = "";
// Output one line until end-of-file
while(!feof($File)) {
    $row = explode(";",fgets($File));
    $substring = "IT0006;IT0017;";
// left string
    $lstr = "";
// right string
    $rstr = "";
    $type = array_intersect($row, $typePers);
    $keys = array_keys($type);
    if($keys == null) $type = $emptyValue;
    else $type = $row[$keys[0]];
    $j = 0;
    for($i=0; $i<count($row); $i++){
        if(in_array($row[$i],$excludeFields)){
            unset($row[$i]);
            $j++;
        }
    }
    for($i=0; $i<22;$i++)$lstr .= $row[$i].";";
    foreach($row as $k => $v)
        if($k > 22)if(!empty($v))$rstr .= $v.";";

    $rstr = substr($rstr,0,-1);
    $substring .= $type;
    $substring .= ";IT0077;NaN;IT0105;";
    $rowfinal .= $lstr.$substring.$rstr;
}
$file = 'test.txt';
// Write the contents back to the file
file_put_contents($file, $rowfinal);
fclose($sapFile);
?>
我只对删除方法有问题。
当数组中有IT0006值时,我会复制IT0105。。。
最后,我必须为CSV文件添加标题列。
例如,我想定义一个标题为:

$header = @('column1','column2',...,'column_n');

并在要以CSV格式导出的文件处添加标题。

重写而不是转换可能更容易。你能编辑问题并解释转换应该做什么吗?添加一个示例输入和所需的输出。我完全同意@vonPryz,不要试图逐个语句将PHP转换为PowerShell语句
$header = @('column1','column2',...,'column_n');