0

I don't know why these commands resulting in extra lines, looks like 2 or 3 lines after the OS caption. How do I rid of the lines after the OS caption?

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

Result output:

Microsoft Windows Server 2012 R2 Standard

BuildNumber : 9600 BuildType : Multiprocessor Free OSType : 18 ServicePackMajorVersion : 0 ServicePackMinorVersion : 0

ikask
  • 318
  • 2
  • 11
  • 23

1 Answers1

0

If you are looking to fetch OS info just use the below

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

Echo "Operating System "
Echo "-------------------------------"
OSCheck

Output

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
Sudheej
  • 1,873
  • 6
  • 30
  • 57
  • Thanks.This is really good, but how can I utilize it with different computer names since I want to check multiple machines? – ikask Nov 29 '16 at 04:58
  • On the computer you want to run remote script 1. Open PS and admin 2. Enable-PSRemoting -Force 3. On both computers, configure the TrustedHosts setting so the computers will trust each other 4. Set-Item wsman:\localhost\client\trustedhosts * 5. Restart-Service WinRM 6. Test the connection Test-WsMan Execute Invoke-Command -ComputerName COMPUTER -ScriptBlock { COMMAND } -credential USERNAME – Sudheej Dec 06 '16 at 18:39