小编cam*_*.rw的帖子

停止PowerShell管道,确保调用end

我要做的是获得一个函数来在达到时间限制时停止管道输入.我创建了一个测试函数如下:

function Test-PipelineStuff
{
    [cmdletbinding()]
    Param(
        [Parameter(ValueFromPipeLIne=$true)][int]$Foo,
        [Parameter(ValueFromPipeLIne=$true)][int]$MaxMins
    )

    begin { 
        "THE START" 
        $StartTime = Get-Date
        $StopTime = (get-date).AddMinutes($MaxMins)
        "Stop time is: $StopTime"
    } 

    process 
    {  
        $currTime = Get-Date
        if( $currTime -lt $StopTime ){
            "Processing $Foo"            
        }
        else{
            continue;
        }
    }

    end { "THE END" }
}
Run Code Online (Sandbox Code Playgroud)

这肯定会阻止管道,但它永远不会调用我的"end {}"块,在这种情况下它是至关重要的.有没有人知道为什么当我使用"继续"停止管道时,我的"end {}"块没有被调用?如果我抛出PipelineStoppedException,行为似乎是相同的.

powershell pipeline powershell-4.0

11
推荐指数
1
解决办法
764
查看次数

为什么Powershell现在总是作为管理员运行?

我正在运行Windows 7,最近安装了更新,因此我可以使用Powershell 3.0.这个过程很顺利,我已经使用Powershell 3大约一个月了.我注意到的一件事是,每次我现在运行Powershell时,它都会以提升的权限运行.我没有右键单击并以管理员身份运行,我只是进行正常的左键单击.当我从"开始"菜单运行,或者当它被固定到任务栏或者我开始它时,会发生这种情况.Powershell 2从未发生这种情况.我没有做任何特别的事情,因为它总是以Admin身份运行,因为我不想总是以Admin身份运行.有没有人对我可以检查的事情有任何建议?

powershell administrator windows-7

5
推荐指数
1
解决办法
3857
查看次数

我可以将用Delphi编写的DLL加载到PowerShell中吗?

我可以通过[Reflection.Assembly]::LoadFile()方法直接在Powershell中使用我在Delphi(Delphi 10)中创建的DLL 吗?我正在尝试,但得到错误:

使用"1"参数调用"LoadFile"的异常:"模块应该包含一个程序集清单.

我能够将Delphi DLL包装在我用C#编写的DLL中并以这种方式使用它,但不愿意,因为它意味着为每个更改而不是一个更改编译两个项目.

这是我目前在Delphi DLL中的代码:

library TestDLL;


procedure TestCall(foo: PChar); stdcall;
begin
end;

exports
  TestCall;

begin
end.
Run Code Online (Sandbox Code Playgroud)

delphi dll powershell

3
推荐指数
1
解决办法
434
查看次数