【问题标题】:powershell command result writing extra lines of space [duplicate]powershell命令结果写入额外的空格行[重复]
【发布时间】:2016-11-29 04:32:06
【问题描述】:

我不知道为什么这些命令会导致额外的行,看起来像操作系统标题后的 2 或 3 行。如何去掉操作系统标题后的线条?

cls
(Get-WmiObject -class Win32_OperatingSystem -ComputerName server1).Caption
Get-WmiObject -Class Win32_OperatingSystem -ComputerName server1 | Select-Object -Property BuildNumber,BuildType,OSType,ServicePackMajorVersion,ServicePackMinorVersion

结果输出:

Microsoft Windows Server 2012 R2 标准版

内部版本号:9600 BuildType : 多处理器免费 操作系统类型:18 服务包主要版本:0 服务包次要版本:0

【问题讨论】:

    标签: powershell lines extra get-wmiobject


    【解决方案1】:

    如果您想获取操作系统信息,请使用以下内容

    Function OSCheck() {
    SystemInfo | Select-String '^OS '
    [System.Environment]::OSVersion.Version
    }
    
    Echo "Operating System "
    Echo "-------------------------------"
    OSCheck
    

    输出

    OS Name:                   Microsoft Windows 7 Enterprise
    OS Version:                6.1.7601 Service Pack 1 Build 7601
    OS Manufacturer:           Microsoft Corporation
    OS Configuration:          Member Workstation
    OS Build Type:             Multiprocessor Free
    

    【讨论】:

    • 谢谢。这真的很好,但我要检查多台机器,如何使用不同的计算机名称?
    • 在您要运行远程脚本的计算机上 1. 打开 PS 和管理员 2. Enable-PSRemoting -Force 3. 在两台计算机上,配置 TrustedHosts 设置,以便计算机相互信任 4. 设置-Item wsman:\localhost\client\trustedhosts * 5. Restart-Service WinRM 6. 测试连接 Test-WsMan Execute Invoke-Command -ComputerName COMPUTER -ScriptBlock { COMMAND } -credential USERNAME
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-14
    • 2013-04-22
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    相关资源
    最近更新 更多