Creating a Function that writes to a file in Power

2019-09-20 18:19发布

So in powershell I know how to write to a file by either using ">test.txt" or by using Out-File but I'm trying to create a function in Powershell.

function Create New Nuspec { out-file test.txt
            <id>$id</id>
            <authors>CME</authors>
            <owners>CME</owners>
            <version>$version</version>
            <description>$filepath</desciption>
            }

So I'm trying to have this function output to a file, eventually an XML file but for now I'm just trying to get it to work.

标签: powershell
1条回答
forever°为你锁心
2楼-- · 2019-09-20 19:13

Maybe something like this?

function CreateNewNuspec { 
param ($outfile, $id, $version, $filepath)

@"
<id>$id</id>
<authors>CME</authors>
<owners>CME</owners>
<version>$version</version>
<description>$filepath</description>
"@ | Out-File $outfile
}

CreateNewNuspec test.txt "ID1" "1.0" "filename.txt" 
查看更多
登录 后发表回答