magritton
12/15/2014 - 1:35 AM

This iterates through a list of files in a directory, parses the name of the file, and the creates a new files based on the parsed name. Thi

This iterates through a list of files in a directory, parses the name of the file, and the creates a new files based on the parsed name. This also is an example of the escape character and new-item, and of a newline

$Files = Get-ChildItem "D:\Program Files (x86)\CQCS\Organizations\ALL\users\opwecqadmin" -Name -Filter "*.eq"

foreach($f in $Files)
{
    $TableName = $f.PSChildName.Replace("_ByDate.eq","")
    $Data = ""
    $Data += "viewpoint native;" + [Environment]::NewLine
    $Data += "list/domain=`"" + $TableName + "`"/nodetail/hold=`"TableItemCounts`"/append" + [Environment]::NewLine
    $Data += "sorted by " + $TableName + ":line_id" + [Environment]::NewLine
    $Data += "end of report" + [Environment]::NewLine
    $Data += "`"" + $TableName + "`"/name=`"TableName`"/width=100" + [Environment]::NewLine
    $Data += "count[" + $TableName + ":Line_id]/width=15/name='ItemCount'" + [Environment]::NewLine

    $NewName = "D:\Program Files (x86)\CQCS\Organizations\ALL\users\opwecqadmin\" + "TC_" + $f.PSChildName.Replace("_ByDate","")
    $TableName
    New-Item $NewName -ItemType File -Force 
    $Data | Out-File $NewName -Encoding ascii
}