如何使用参数将路径文件作为输入数据提供给PowerShell中的其他脚本? [英] How to use argument to get path file as an input data to other script in powershell?

查看:293
本文介绍了如何使用参数将路径文件作为输入数据提供给PowerShell中的其他脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 0 


我想读取2个文本文件(Byte2.txt和FB.txt),但我不想把路径放在脚本,我想在从命令行运行脚本到解析脚本路径时使用参数。我的命令,当我从命令行运行脚本时:

$ PowerShell.exe Script.ps1 arg1 arg2

arg1表示Byte.txt的路径,arg2表示路径FB.txt

我尝试过:

< pre>
$ file = $ Args [0]
$ Data = $ Args [1]
$ file_2 = Get-Content
$ file_2
$ Data_2 = Get -content
$ Data_2



我从cmd执行该脚本:



 $ PS.exe Script.ps1 C:\ User \ Pyt.txt C:\ User \ NF.txt 

解决方案

PowerShell.exe Script.ps1 arg1 arg2

arg1表示Byte.txt的路径,arg2表示FB.txt的路径

我尝试过:

< pre>


file =


Args [0]

0


I want to read a 2 of text file (Byte2.txt and FB.txt), but I dont want to put the path on the script, I want to use argument when I run the script from command line to parsing the path to my script. My expextation, when I run the script from command line :

$PowerShell.exe Script.ps1 arg1 arg2

arg1 represent the path of Byte.txt and arg2 represent the path of FB.txt

What I have tried:

<pre>
$file = $Args[0]
$Data = $Args [1]
$file_2 = Get-Content " "
$file_2
$Data_2 = Get-content " "
$Data_2


I execute that script from cmd :


$PS.exe Script.ps1 C:\User\Byte.txt C:\User\FB.txt

解决方案

PowerShell.exe Script.ps1 arg1 arg2 arg1 represent the path of Byte.txt and arg2 represent the path of FB.txt What I have tried: <pre>


file =


Args[0]


这篇关于如何使用参数将路径文件作为输入数据提供给PowerShell中的其他脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆