小编mbx*_*mbx的帖子

为什么将 Powershell 设置为 set-executionpolicy remotesigned 失败?

使用 Win7-32​​bit 和 Powershell ISE,我尝试运行刚刚保存的脚本(假设包含一个简单的 cls)。我收到错误消息,通常的“get-help about_signing”建议禁止执行脚本。

当使用“set-executionpolicy remotesigned”来解决时,我得到了一个对话来验证我是否确定。但如果我接受另一个错误出现:

acces to registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" denied
    + set-executionpolicy <<<<  remotesigned
        + CategoryInfo          : NotSpecified: (:) [Set-ExecutionPolicy], UnauthorizedAccessException
        + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
Run Code Online (Sandbox Code Playgroud)

我该怎么做,以用户身份运行保存的脚本(或作为日常服务自动运行)?

powershell security-policy

15
推荐指数
2
解决办法
4万
查看次数

Powershell 中的 grep

使用 Powershell 内置函数来模拟grep类似行为的最简单/舒适的方法是什么?

在脚本中我使用这样的东西

dir "*.filter" | foreach-object{
    $actfile = $_
    $readerrorfile = [System.IO.Path]::GetTempFileName()
    $found = $false
    $content = Get-Content $actfile 2> $readerrorfile
    $readerror = Get-Content $readerrorfile
    if($readerror -match "Error"){
        echo "Error while reading from file $actfile"
        echo $readerror
        del $readerrorfile
        Write-Host "stopping execution"
        exit
    }else{
        del $readerrorfile
        if($content -match "keyword|regex"){
            echo "found in $actfile"
            $found = true;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我相当确定有一个更简单/更短的版本,也许是单行的。那么,最好的方法是什么grep

powershell grep

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

避免在内存不足的情况下杀死 SSH

当我的服务器遇到内存不足时,它通常会杀死多个应用程序。如何防止杀死 SSH?因为通常,当发生这种内存不足错误时,我的 SSH 会像这样损坏:

I connect to ssh server.
Enter username
Enter password
Run Code Online (Sandbox Code Playgroud)

然后我等待

我等

等等...

哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇

进而:

Connection timed out.
Run Code Online (Sandbox Code Playgroud)

有什么办法可以防止这种情况吗? 如何提高进程的优先级?

ssh priority out-of-memory

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