Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows Powershell脚本未将数据输出到ISE之外的文件_Windows_Powershell_Batch File - Fatal编程技术网

Windows Powershell脚本未将数据输出到ISE之外的文件

Windows Powershell脚本未将数据输出到ISE之外的文件,windows,powershell,batch-file,Windows,Powershell,Batch File,我知道其他人也有类似的问题,但没有一个是这样的。我制作了一个ps1脚本,将一个XML对象文件转换成一个CSV文件,其中包含表示某些数据的行。昨晚我可以运行批处理文件并转换文件,但今天早上从批处理运行时它保存了一个空的CSV文件,但在Powershell ISE中运行时效果良好 我使用-STA模式从批处理文件运行它,以使其能够打开对话框窗口: powershell -sta C:\Users\*******\Downloads\JiraXMLtoCSV.ps1 下面是脚本(很难让这个代码块lol

我知道其他人也有类似的问题,但没有一个是这样的。我制作了一个ps1脚本,将一个XML对象文件转换成一个CSV文件,其中包含表示某些数据的行。昨晚我可以运行批处理文件并转换文件,但今天早上从批处理运行时它保存了一个空的CSV文件,但在Powershell ISE中运行时效果良好

我使用-STA模式从批处理文件运行它,以使其能够打开对话框窗口:

powershell -sta C:\Users\*******\Downloads\JiraXMLtoCSV.ps1
下面是脚本(很难让这个代码块lol成为“}”的借口):

}

如果您需要一些示例XML来帮助我了解我做错了什么:

    <rss version="0.92">
    <channel>
    <title>XML Export</title>
    <link>...</link>
    <description>An XML representation of a search request</description>
    <language>en-us</language>
    <issue start="0" end="7" total="7"/>
    <build-info>...</build-info>
    <item>
    <title>[AJT-46] another new story</title>
    <project id="1652" key="AJT">Advanced Training</project>
    <description/>
    <environment/>
    <key id="220774">AJT-46</key>     
    <status id="16615" iconUrl="https://website.com/" description="Desc text">To Do</status>
    <statusCategory id="2" key="new" colorName="gray"/>
    <labels></labels>
    <created>Tue, 5 Jun 2018 11:25:38 -0400</created>
    <updated>Tue, 5 Jun 2018 11:29:00 -0400</updated>
    <due/>
    </item>
    </channel>
    </rss>

XML导出
...
搜索请求的XML表示形式
美国英语
...
[AJT-46]另一个新故事
高级培训
AJT-46
做
2018年6月5日星期二11:25:38-0400
2018年6月5日星期二11:29:00-0400

它是昨晚工作,现在不工作,当我出现在今天早上,所以没有改变,我知道,我也没有重新启动。它仍然在Powershell ISE中工作,这很好,但我需要为我制作它的人使用批处理文件方法。感谢您的任何帮助、建议等!谢谢

我所做的更改,现在可以使用了,双换行符分隔:

# Invoke the file-picker function and obtain input file 
[Xml]$inputFile = Get-JiraXMLFile;


# Grab all the items we exported, ignore the header info
if ( $inputFile ) {
    #$XmlComments = Select-Xml "//comment()" -Xml $inputFile;
    #$inputFile.RemoveChild($XmlComments);
    $items = Select-Xml "//rss/channel/item" -Xml $inputFile;
}


# Iterate over items and grab important info to be put into CSV format
foreach ( $item in $items ){
# Create a new hash object
$issue = @{}; 


# Gather wanted attributes
if( $item.Node.key){
    $issue.Key = $item.Node.key.InnerXML;
}

不太会批处理,所以请耐心听我说……您是否使用了任何特定于Powershell的cmdlet,这可能会让vanilla批处理变得疯狂?此外,您在这里使用的是对象。常规的cmd批处理不是只基于文本吗?很可能在ISE会话中内存中有一些内容。话虽如此,我看不到Get SaveFile返回值的任何地方。也许它只是与ExecutionPolicy有关。。如果您在de ISE中运行它,但可以作为其他用户从批处理文件运行,则此用户可能没有这样做的权限。您可以尝试
powershell-sta-File“C:\Users\******\Downloads\JiraXMLtoCSV.ps1”-ExecutionPolicy Bypass
p.s.我双引号引用了文件的路径,因为如果其中有空间,批处理文件将不知道在哪里找到它。此外,如果计算机的Powershell版本为3.0或更高版本,则不需要指定-Sta开关,因为它是3.0及更高版本的默认值。我一直在尝试,发现这是批处理端的问题。现在它不接受Powershell System.Xml,所以它肯定讨厌Xml。我不知道该怎么办了。是否有更好的方法从单独的文件以STA模式运行powershell 2脚本?分开,因为显然脚本可以在STA模式下运行,我铸造了这个
#调用文件选择器函数并获取输入文件[Xml]$inputFile=Get JiraXMLFile,然后执行以下操作:`$items=selectxml//rss/channel/item“-Xml$inputFile;`然后必须访问$items.Node才能获取值。不知道我在做什么,但我希望有一天这能帮助别人
    <rss version="0.92">
    <channel>
    <title>XML Export</title>
    <link>...</link>
    <description>An XML representation of a search request</description>
    <language>en-us</language>
    <issue start="0" end="7" total="7"/>
    <build-info>...</build-info>
    <item>
    <title>[AJT-46] another new story</title>
    <project id="1652" key="AJT">Advanced Training</project>
    <description/>
    <environment/>
    <key id="220774">AJT-46</key>     
    <status id="16615" iconUrl="https://website.com/" description="Desc text">To Do</status>
    <statusCategory id="2" key="new" colorName="gray"/>
    <labels></labels>
    <created>Tue, 5 Jun 2018 11:25:38 -0400</created>
    <updated>Tue, 5 Jun 2018 11:29:00 -0400</updated>
    <due/>
    </item>
    </channel>
    </rss>
# Invoke the file-picker function and obtain input file 
[Xml]$inputFile = Get-JiraXMLFile;


# Grab all the items we exported, ignore the header info
if ( $inputFile ) {
    #$XmlComments = Select-Xml "//comment()" -Xml $inputFile;
    #$inputFile.RemoveChild($XmlComments);
    $items = Select-Xml "//rss/channel/item" -Xml $inputFile;
}


# Iterate over items and grab important info to be put into CSV format
foreach ( $item in $items ){
# Create a new hash object
$issue = @{}; 


# Gather wanted attributes
if( $item.Node.key){
    $issue.Key = $item.Node.key.InnerXML;
}