【问题标题】:powershell get computer name where is script located when running from another computerpowershell 从另一台计算机运行时获取脚本所在的计算机名称
【发布时间】:2015-03-28 10:27:48
【问题描述】:

我有可以从另一台计算机执行的脚本。

如何获取位置脚本的comptername?只是名称,不是完整路径(因为脚本可以分发到任何地方)谢谢

【问题讨论】:

    标签: powershell computer-name


    【解决方案1】:

    我自己解决了。 :-) 希望对某人有所帮助。

    $scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
    [string[]]$sth = $scriptPath.Split('\',[System.StringSplitOptions]::RemoveEmptyEntries)
    $servername = $sth[0]
    

    【讨论】:

    • 更多 PoSh:$servername = ($scriptPath -replace '^\\\\' -split '\\')[0].
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 2010-10-22
    • 2020-10-13
    • 2017-01-01
    • 2017-04-29
    • 2020-04-09
    相关资源
    最近更新 更多