[英]Powershell return different results running the same script from c#
我正在尝试运行一个简单的脚本来获取文件属性。
string script = @"$path = 'C:\Temp\Indexing\Asm1.asm'
$shell = New-Object -COMObject Shell.Application
$folder = Split-Path $path
$file = Split-Path $path -Leaf
$shellfolder = $shell.Namespace($folder)
$shellfile = $shellfolder.ParseName($file)
0..500 | Foreach-Object { '{0} = {1}' -f $shellfolder.GetDetailsOf($null, $_), $shellfolder.GetDetailsOf($shellfile, $_).toString()}";
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(script);
pipeline.Commands.Add("Out-String");
Collection<PSObject> results = pipeline.Invoke();
runspace.Close();
在 powershell 中运行时,我得到更多的属性结果,这些结果在通过代码运行时为空。 这似乎是一个访问问题。 任何帮助都感激不尽!
尝试添加#!/usr/bin/env pwsh
作为脚本的第一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.