小编Ale*_*les的帖子

如何让 winrm 默认使用 powershell 7 进行远程会话

随着 powershell 7 的发布,似乎是时候超越 ps 5.1,所以我已经在几台服务器上安装了它来试一试。

但是,当我使用 ps7 从我的电脑创建到这些服务器的会话时,我总是在远程机器上运行 ps5.1。

Invoke-Command -ComputerName name -ScriptBlock { 
        Write-Host $env:COMPUTERNAME
        $PSVersionTable.PsVersion
    }
Run Code Online (Sandbox Code Playgroud)

输出 5.1.17763.316。任何想法如何让远程会话在默认情况下最好使用 7.0.0 版?

更新在 这方面取得了一些进展,所以尽管我会分享。

在 powershell 7 的远程机器上运行以下命令

Enable-PSRemoting
Run Code Online (Sandbox Code Playgroud)

这将创建一些 PsSessionConfigurations,您可以使用以下命令查看它们。

Get-PSSessionConfiguration
Run Code Online (Sandbox Code Playgroud)

现在您可以执行以下操作以从 powershell 7 创建会话

Invoke-Command -ComputerName ServerName -ScriptBlock { $PsVersionTable.PSVersion } -ConfigurationName Powershell.7
$session = New-PSSession ServerName -ConfigurationName Powershell.7
Invoke-Command -Session $session -ScriptBlock { $PsVersionTable.PSVersion } 
Run Code Online (Sandbox Code Playgroud)

这现在在远程会话中使用 ps 7,快乐的日子。现在如何在默认情况下实现这一点......?从这个github 问题

将默认的 microsoft.powershell 端点设置为他们选择的任何 PowerShell

我认为这就是我想要做的,因此切换回 ps 5.1 并尝试了以下命令:

Get-PSSessionConfiguration -Name microsoft.powershell | Set-PSSessionConfiguration -PSVersion 7.0 …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-remoting powershell-6.0

6
推荐指数
1
解决办法
1729
查看次数

如何在NanoServer上安装根证书

有一些指南展示了如何执行此操作,但它们是不久前的,我似乎找不到它们所指的实用程序 certoc.exe。这是否已从 Nanoserver 的更高版本中删除?

https://joshuachini.com/2018/02/08/how-to-import-an-enterprise-certificate-into-a-windows-container/

https://www.ntweekly.com/2017/01/30/install-self-signed-certificate-on-windows-nano-server-2016/

https://blogs.technet.microsoft.com/nanoserver/2015/11/19/hands-on-packaging-and-installing-your-first-windows-server-apps-on-nano-server/

有人知道我应该在哪里获得这个实用程序吗?

我在这里发现了另一个小线索 https://github.com/PowerShell/CertificateDsc/issues/45

这种情况回避了 Nano 服务器中可用的 Import-Certificate 命令。虽然我也没有找到。

任何帮助都会得到应用,干杯。

PS C:\> docker run microsoft/nanoserver:1803_KB4338819 certoc.exe
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: container 3f732602c6d8fbbf9370613971a7f40993a54bc33870d3040bf5e9c2fec8969c encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: {"CommandLine":"certoc.exe","User":"ContainerUser","WorkingDirectory":"C:\\","CreateStdInPipe":true,"CreateStdOutPipe":true,"CreateStdErrPipe":true,"ConsoleSize":[0,0]}.

PS C:\> docker run -it microsoft/powershell:6.0.4-nanoserver-1803_kb4338819 certoc.exe
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: container 285d821dccac930df5681e73842f8ce2bac812f361a6b9d14b00dcb4901a9141 encountered an error during CreateProcess: failure in a Windows system call: The system …
Run Code Online (Sandbox Code Playgroud)

powershell docker nano-server

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

Strange Typescript编译错误:'this'无法在当前位置引用,有人可以解释一下吗?

我认为这有一个很好的理由,但对我来说似乎很奇怪.请将以下代码作为问题的示例.

class Foo {
    constructor(referenceMethod: () => void) {
    }
}

class Bar extends Foo {

    TestProperty: string = "boo";

    constructor() {
        super(this.ReferenceMethod);
    }

    ReferenceMethod() {

    }
}
Run Code Online (Sandbox Code Playgroud)

这会产生编译器错误

'this'无法在当前位置引用.

如果我们初始化TestProperty构造函数内部,编译器很高兴并且世界按预期旋转,当然如果我们不将referenceMethod的引用传递给超级调用,我们可以在构造函数外部设置TestProperty.

但是我只是不明白为什么一起做这两件事会导致问题.如果有人能够阐明这一点,以帮助我的理解将不胜感激.

typescript

2
推荐指数
1
解决办法
2564
查看次数