find string filter the systeminfo output - windows

Use findstr to filter a string OS Version:
C:\Windows\system32>systeminfo | findstr "OS Version"
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19044 N/A Build 19044
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
BIOS Version: American Megatrends Inc. 4.6.5, 2020/11/2
Notice: systeminfo | findstr "OS Version:" has the same result.
Why the output can't be as below:
OS Version: 10.0.19044 N/A Build 19044
Why the output contains many other lines unrelated to the matching string OS Version?

Because "OS Version" matches both "OS" and "Version". If you want to match the entire string "OS Version" instead of either word, this is what you want:
systeminfo | findstr "OS\ Version"
And that will match "OS Version" and "BIOS Version" lines. So filter out the BIO version thing like this:
systeminfo | findstr "OS\ Version" | findstr /v BIOS

Related

Can't grant permission to IIS_IUSRS on windows container

I'm building a image, which was made by microsoft/aspnet and builder OS:
C:\> systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name: Microsoft
OS Version: 10.0.17763 N/A Build 17763
, I got error after running RUN icacls 'C:\inetpub\wwwroot\' /grant 'IIS_IUSRS:(F)'
Invalid parameter "'IIS_IUSRS:(F)'"
The command 'cmd /S /C icacls 'C:\inetpub\wwwroot\' /grant 'IIS_IUSRS:(F)'' returned a non-zero code: 87
But under the base image which was made by microsoft/aspnet and builder OS
PS C:\> systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name: Microsoft
OS Version: 10.0.18362 N/A Build 18362
Was totally OK, anyone knows why?
Your codes are okay but a very lil mistake
Try this
icacls '\inetpub\wwwroot\' /grant "IIS_IUSRS":f
Hope your problem will solve.

How to batch or cli automate sigcheck.exe on running processes?

I'm trying to generate a list of running processes (full executable path), and then loop through that listing and perform a SysInternals "sigcheck.exe" against each of the files.
For some reason this isn't performing as expected and I'm unsure if it's due to my processing of the input file, or the format of output that wmic creates. Ideally, I'd like to get this working as a batch script first and then attempt to convert it to a cli one-liner.
Below is the code I'm currently trying:
setlocal enabledelayedexpansion
#echo off
wmic process get executablepath /format:csv | more > c:\windows\temp\pslist.txt
for /f "skip=5 tokens=1,2 delims=," %%a in (c:\windows\temp\pslist.txt) do (
echo %%b
sigcheck.exe -accepteula -r -e "%%b"
)
ENDLOCAL
This uses "wmic.exe process" to build a list and passes just the "executablepath" to "sigcheck.exe". The "threadcount" is there as a trick - since WMIC has it's infamous extra-CR, asking for 1 extra and unneeded attribute creates markers in the output.....the commas. The "for" command chops the WMIC output at the commas, which is how just the "executablepath" can be pulled out without any extra CRs.
CMD:
for /f "tokens=2 delims=," %A in ('wmic process where "not executablepath=null" get executablepath^,threadcount /format:csv') do #sigcheck.exe -accepteula -r -e "%A"
OUTPUT (partial for brevity sake):
Sigcheck v2.72 - File version and signature viewer
Copyright (C) 2004-2019 Mark Russinovich
Sysinternals - www.sysinternals.com
c:\program files (x86)\google\chrome\application\chrome.exe:
Verified: Signed
Signing date: 7:47 PM 2/28/2019
Publisher: Google LLC
Company: Google Inc.
Description: Google Chrome
Product: Google Chrome
Prod version: 72.0.3626.121
File version: 72.0.3626.121
MachineType: 64-bit
Sigcheck v2.72 - File version and signature viewer
Copyright (C) 2004-2019 Mark Russinovich
Sysinternals - www.sysinternals.com
c:\windows\system32\windowspowershell\v1.0\powershell.exe:
Verified: Signed
Signing date: 5:26 PM 4/11/2018
Publisher: Microsoft Windows
Company: Microsoft Corporation
Description: Windows PowerShell
Product: Microsoft« Windows« Operating System
Prod version: 10.0.17134.1
File version: 10.0.17134.1 (WinBuild.160101.0800)
MachineType: 64-bit
Sigcheck v2.72 - File version and signature viewer
Copyright (C) 2004-2019 Mark Russinovich
Sysinternals - www.sysinternals.com

Get only ethernet MAC-address via command prompt

I use 'ipconfig /all' or 'getmac /v' to get all NIC physical addresses.
But the problem is, generally a computer has more than one NIC card. Also, there are some virtual MAC addresses like Microsoft virtual wifi hotspot NIC which shows only when wifi hotspot is on.
So, how can I collect only the address corresponding to ethernet via cmd?
This command fetches MAC addresses of physical ethernet network devices:
wmic path Win32_NetworkAdapter where "PNPDeviceID like '%PCI%' AND AdapterTypeID='0'" get name, MacAddress
if you want to fetch virtual ones as well then use this:
wmic path Win32_NetworkAdapter where "AdapterTypeID='0'" get name, MacAddress
or this one for fetching all the MAC addresses of all network devices:
wmic path Win32_NetworkAdapter get name, MacAddress
Just in case you are interested how it works:
We are using WMIC tool provided by Windows to fetch adapter info from Win32_NetworkAdapter.
Then filter ethernet adapters by AdapterTypeID=0 as 0 corresponds to ethernet type.
Finally filter physical devices with PNPDeviceID like '%PCI% since they are attached to PCI.
You might also want to look at the result of whole Win32_NetworkAdapter and play with it with this command:
wmic path Win32_NetworkAdapter
I advise to you use powershell because very powerful than cmd
Get-CimInstance win32_networkadapterconfiguration | select description, macaddress | where {$_.MACAddress -ne $n
ull }
output :
description macaddress
----------- ----------
RAS Async Adapter 20:41:53:59:4E:FF
Realtek PCIe GBE Family Controller 18:03:73:65:64:AB
VMware Virtual Ethernet Adapter for VMnet1 00:50:56:C0:00:01
VMware Virtual Ethernet Adapter for VMnet8 00:50:56:C0:00:08
that command in powershell select all macaddress for device enable your machine that included vmware but we can do more filter for example
Get-CimInstance win32_networkadapterconfiguration | select description, macaddress | where {$_.MACAddress -ne $n
ull } | where {$_.Description -match "Realtek" }
output:
description macaddress
----------- ----------
Realtek PCIe GBE Family Controller 18:03:73:65:64:AB
but if your just run in cmd you should encode this command in powershell like this
$script={ Get-CimInstance win32_networkadapterconfiguration | select description, macaddress | where {$_.MACAddr
ess -ne $null } | where {$_.Description -match "Realtek" } }
[System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes( $script))
output encoded command for use in cmd
IABHAGUAdAAtAEMAaQBtAEkAbgBzAHQAYQBuAGMAZQAgAHcAaQBuADMAMgBfAG4AZQB0AHcAbwByAGsAYQBkAGEAcAB0AGUAcgBjAG8AbgBmAGkAZwB1AHI
AYQB0AGkAbwBuACAAfAAgAHMAZQBsAGUAYwB0ACAAZABlAHMAYwByAGkAcAB0AGkAbwBuACwAIABtAGEAYwBhAGQAZAByAGUAcwBzACAAfAAgAHcAaABlAH
IAZQAgAHsAJABfAC4ATQBBAEMAQQBkAGQAcgBlAHMAcwAgAC0AbgBlACAAJABuAHUAbABsACAAfQAgACAAfAAgAHcAaABlAHIAZQAgAHsAJABfAC4ARABlA
HMAYwByAGkAcAB0AGkAbwBuACAALQBtAGEAdABjAGgAIAAiAFIAZQBhAGwAdABlAGsAIgAgAH0AIAA=
in cmd i use this and get mac
powershell -encodedcommand IABHAGUAdAAtAEMAaQBtAEkAbgBzAHQAYQBuA
GMAZQAgAHcAaQBuADMAMgBfAG4AZQB0AHcAbwByAGsAYQBkAGEAcAB0AGUAcgBjAG8AbgBmAGkAZwB1A
HIAYQB0AGkAbwBuACAAfAAgAHMAZQBsAGUAYwB0ACAAZABlAHMAYwByAGkAcAB0AGkAbwBuACwAIABtA
GEAYwBhAGQAZAByAGUAcwBzACAAfAAgAHcAaABlAHIAZQAgAHsAJABfAC4ATQBBAEMAQQBkAGQAcgBlA
HMAcwAgAC0AbgBlACAAJABuAHUAbABsACAAfQAgACAAfAAgAHcAaABlAHIAZQAgAHsAJABfAC4ARABlA
HMAYwByAGkAcAB0AGkAbwBuACAALQBtAGEAdABjAGgAIAAiAFIAZQBhAGwAdABlAGsAIgAgAH0AIAA=
output:
description macaddress
----------- ----------
Realtek PCIe GBE Family Controller 18:03:73:65:64:AB
#ECHO OFF
SETLOCAL enabledelayedexpansion
FOR /f "delims=" %%a IN ('getmac /v ^|find /i "local area conn" ') DO (
FOR %%b IN (%%a) DO (
SET element=%%b
IF "!element:~2,1!!element:~5,1!!element:~8,1!"=="---" set mac=%%b
)
)
ECHO found %mac%
GOTO :EOF
This should provide the information required, but it would have been better had you provided sample output from your machine as your experience may not be exactly reproduced on others' installations.
on commandline:
for /f %i in ('wmic nic get MACAddress ^|find ":"') do #echo %i
or
for /f %i in ('getmac^|find "-"') do #echo %i
for use in a batchfile, use %%i instead of %i
To only get the active network card's MAC-address using Powershell:
(Get-WmiObject win32_networkadapterconfiguration -ComputerName $env:COMPUTERNAME | Where{$_.IpEnabled -Match "True"} | Select-Object -Expand macaddress) -join ","
You can try this :
netsh interface ip show addresses "Ethernet"

How can I programatically check that I am running Windows 8.1?

How can I programatically check that I am running Windows 8.1 using cmd.exe or PowerShell?
Powershell
get-wmiobject win32_operatingsystem will return several properties you can use to check the OS.
get-wmiobject win32_operatingsystem|select-object name,caption,buildnumber,version|format-list
name : Microsoft Windows 8.1 Enterprise|C:\WINDOWS|\Device\Harddisk0\Partition2
caption : Microsoft Windows 8.1 Enterprise
buildnumber : 9600
version : 6.3.9600
CMD
wmic os get caption /value|find "="
to put it into a variable:
for /f %%i in ('wmic os get caption /value^|find "="') do set version=%%i
Another method using PowerShell:
(Get-Command -Name $env:windir\system32\ntoskrnl.exe).FileVersionInfo.FileVersion -match '6.3.9600';
This command returns $true or $false. To be honest, alroc's is the ideal solution, in my opinion. This is just an alternative.

Find out windows version from non-privileged user command line

I need a way to find out what version of windows I'm running in using simple command line tools (no powershell). I need it to work from a non-privileged user, and I need to be able to parse out the difference between Windows XP, Vista, server 2008, and 7. I'm currently using:
wmic os get Caption but that fails when the user doesn't have permissions to run wmic.
Update:
To clarify, I need this command to not break with different service pack levels, etc. which probably rules out parsing a specific version number. Also if you look at this list of windows versions, you'll see that the numbers reported on Windows 7 and server 2008 r2 are the same.
I solved this problem by parsing the output of:
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "ProductName"
systeminfo command shows everything about the os version including service pack number and the edition you are using.
C:\>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name: Microsoft Windows 7 Enterprise
OS Version: 6.1.7601 Service Pack 1 Build 7601
Reference: Find Windows version from command prompt
You can use ver. I'm on a school computer with a non-privileged command prompt, and it gives me Microsft Windows [Version 6.1.7601]. I'm sure you'd be able to sort out Vista and XP from the number you get.
cmd displays the Windows version when started:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Joey>_
This is also a similar line as the one ver spits out, indeed.
One option then might be
echo exit|cmd|findstr Windows
another
cmd /c ver
depending on whether you have a pipeline or not.
if not CMDEXTVERSION 2 (
echo Error: This batch requires Command Extensions version 2 or higher
exit /b 1
)
FOR /F "usebackq tokens=4 delims=] " %%I IN (`ver`) DO for /F "tokens=1,2 delims=." %%J IN ("%%I") do set WindowsVersion=%%J.%%K
if "%WindowsVersion%" LSS "6.1" (
echo Error: This batch requires Windows 7 SP1 or higher
exit /b 1
)
You can get the SysInternals and install onto your C:\ directory. After that you can then go to a command prompt and use the command PSINFO.
It is great because it lets me query any PC on the network (that I have access to). At the command prompt you type: PSINFO \exactnameofcomputer
(PSINFO whack whack exactnameofcomputer)
Then hit enter. It will take a moment or two to report back, depending on where that computer is located at.

Resources