C# Powershell返回从c运行相同脚本的不同结果#
我正在尝试运行一个简单的脚本来获取文件属性C# Powershell返回从c运行相同脚本的不同结果#,c#,powershell,shell,file,attributes,C#,Powershell,Shell,File,Attributes,我正在尝试运行一个简单的脚本来获取文件属性 string script = @"$path = 'C:\Temp\Indexing\Asm1.asm' $shell = New-Object -COMObject Shell.Application $folder = Split-Path $path $file = Split-
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();
string script=@“$path='C:\Temp\index\Asm1.asm”
$shell=新对象-COMObject shell.Application
$folder=拆分路径$Path
$file=拆分路径$Path-Leaf
$shellfolder=$shell.Namespace($folder)
$shellfile=$shellfolder.ParseName($file)
0..500 | Foreach对象{{{0}={1}'-f$shellfolder.GetDetailsOf($null,$\),$shellfolder.GetDetailsOf($shellfile,$\).toString();
Runspace Runspace=RunspaceFactory.CreateRunspace();
Open();
Pipeline Pipeline=runspace.CreatePipeline();
pipeline.Commands.AddScript(脚本);
pipeline.Commands.Add(“输出字符串”);
收集结果=pipeline.Invoke();
runspace.Close();
在powershell中运行时,我会得到更多属性结果,而在代码中运行时这些结果是空的。
这似乎是一个访问问题。
任何帮助都将不胜感激 尝试添加
#/usr/bin/env pwsh
作为脚本的第一行。我唯一的猜测是将$env:UserName
作为脚本运行的用户进行检查。。也许这会把你引向正确的方向。。