I want to know if there is a certain command that you can type into cmd to print system information, such as the RAM, hard drive storage, OS, etc. I have looked around but cannot find anything. If there is one, please give me the syntax and an example of using it. Thanks!
Windows Management Instrumentation (WMI) might be interesting for you.
E.g. wmic cpu get Name prints information about CPU
See: http://www.deepakg.com/blog/2007/08/using-wmic-for-gathering-system-info/, http://blogs.technet.com/b/askperf/archive/2012/02/17/useful-wmic-queries.aspx and https://superuser.com/questions/334641/whats-the-equivalent-command-of-wmic-memlogical-in-windows-7
You could also use systeminfo
start "" /w "C:\Program Files\Common Files\Microsoft Shared\msinfo\msinfo32.exe" /report "%temp%\msinfo.txt" /categories +all & more "%temp%\msinfo.txt"
Plus these are some other commands. Check the help on each /?.
nslookup -type=ANY www.smh.com.au
vssadmin list shadowstorage
winsat features -eef -v
SCHTASKS /query /fo:list
whoami
hostname
quser.exe
ipconfig
driverquery.exe /fo list
mrinfo
gpresult.exe
openfiles.exe
netstat
powercfg.exe
QUERY USER /server:myserver
tasklist
Related
I want to call (execute) a cmd or ps1 script remotely from one Windows 2016 Server 2016 on another. The problem is that script access to a \\network-share is denied.
Reproduce:
(1) a batch or ps1 script with specific Domain-User to \\network-share is successful:
dir \\network-share results in what it should.
(2) try to execute this script from another server via wmic or ps1 with the same user that has access to \\network-share (wmic /node:"node" /user:"domain\usr" /password:"pwd" process call create "cmd.exe /c C:\temp\cmd.bat").
The cmd.bat contains: dir \\network-share or dir \\<UNC-FQDN>\share or dir \\<IP>\share and always gets „Access is denied“ although domain\usr itself has access to the \\network-share.
(3) the identical routine (2) with dir C:\temp runs like expected.
Already tried some registry keys, e.g.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies]
DisableLoopbackCheck
DisableStrictNameChecking
BackConnectionHostNames
LocalAccountTokenFilterPolicy
Maybe one of those is needed on both machines and I did not try every option but to understand what might be the problem here could help I guess.
So, thx & Kind Regards :-)
In the meantime I found two ways to overcome the problem:
a) using Sysinternals PsExec.exe -u domain\user -p pwd -i \\node C:\temp\cmd.bat
b) Create a Scheduled Task on the target machine that can be executed remotely by C:\Windows\System32\schtasks.exe /run /tn "name of the task" /s node /u domain\user /p pwd
Maybe this will help somebody else.
In order to write a Windows batch-file, I want to capture a specific URL address contained in a web page.
To be more precise, the URL address sought is targetting the latest Windows Anaconda file, so this address is changing with time and versions.
Therefore I am looking for a manner to capture automatically this information.
With linux a command to do so can be
AnacondaLink=`wget -O - https://www.anaconda.com/distribution/ 2>/dev/null | sed -ne 's#.*\(https:\/\/repo\.anaconda\.com\/archive\/Anaconda3-.*-Linux-x86_64\.sh\)\">64-Bit (x86) Installer.*#\1#p'`
Does anyone know how to do such equivalent command on Windows ?
I tried to pipe bitsadmin with findstr but the command bitsadmin do not even start when I do
bitsadmin /transfer myDownloadJob /download /priority normal https://www.anaconda.com/distribution/ %UserProfile%/Downloads/file.txt
Not a full working example but an idea how it could be accomplished.
bitsadmin /transfer "anaconda" /DYNAMIC https://www.anaconda.com/distribution/ "%CD%\anaconda.txt"
type anaconda.txt | more /P >anaconda-crlf.txt
findstr "^.*https://repo.*x86_64\.exe.*$" anaconda-crlf.txt
Line 2 ensures that the line ending is CR+LF so that findstr works correctly with ^$ regex.
I'm trying to use a batch FOR loop inside a psexec. I need to make a script that offers me the possibility to choose the subfolders (I store the items in %list_of_items%) in %local_folder% that are needed to be copied with ncftpput on remote server. I cannot put the entire psexec inside the loop because I dont want to insert every time the password.
The piece of code:
psexec \\remote_server -u DOMAIN\user cmd /c FOR %%i IN "%list_of_items%" DO ("ncftpput -f c:\folders\file_with_creds.cfg -R remote_folder/ %local_folder%/%%i")
Example
I have:
%local_folder%\folder111
%local_folder%\folder222
%local_folder%\folder333
I choose to copy the items folder111 and folder333 so I store them in %list_of_items%. For every item in the list I need to run ncftpput to transfer to remote server the folder but doesnt work....
The error:
"folder111" was unexpected at this time.
cmd exited on remote_server with error code 1.
Can you help me please to find what I'm doing wrong?
Thank you.
I've gotten some help with an earlier part of this batch file, but now I'm having trouble with the final component.
I've tried a few things with no success. I tried changing the CRLF to LF which did nothing. I also tried rephrasing the commands a few ways but I am still not getting anywhere. The following is my main batch file.
#echo on
REM delete deauth command file
SET OutFile="C:\temp\Out2.txt"
IF EXIST "%OutFile%" DEL "%OutFile%"
plink -v -ssh *#x.x.x.x -pw PW -m "c:\temp\WirelessDump.txt" > "C:\temp\output.txt"
setlocal
for /f %%a in (C:\temp\output.txt) do >> "Out2.txt" echo wir cli mac-address %%a deauth forced
REM Use commands in out2 to deauth
plink -v -ssh *#x.x.x.x -pw PW -m "c:\temp\Out2.txt"
pause
Below this sentence is the command found in Out2 which I think is giving the actual trouble. The number of lines varies but they are all this particular command just with differing MACs.
wir cli mac-address xxxx.xxxx.xxxx deauth forced
If Out2 has only a single line it runs fine, no issues. But when there are multiple lines, it fails with an error stating that the Line has an invalid autocommand. It's almost as if it was reading it as one contiguous command. As I mentioned above I changed from CRLF to LF hoping IOS would like it better, but that failed. I've tried adding extra lines between the commands, and I've tried calling the login every time from that file.
I am hoping that there is a way to tailor the commands to pass all lines one at a time to keep this down to a minimum of files.
I had another thought but it is kinda/very clunky. If there was a way to output each of those MAC deauth commands to their own file in a saperate folder (out1, out2, out3), and have the BAT able to run all the randomly generated files in that folder so that each one is a separated plink session.
Let me know if I need to change/add/elaborate on anything. Thanks in advance for anything you guys are willing to help with. I appreciate it.
EDIT: Martin has pointed out what the limitation actually is. It appears to be a limitation on Cisco to accept blocks of commands through SSH. So I still have the same question really, I just need some help figuring a workaround to this issue. I'm thinking the multiple file solution I mentioned above may have some possibility. But I'm too much of a noob to know how to make that work. I'll update if I have any breakthroughs though. Thanks for any contributions!
It's actually a known limitation of Cisco, that it does not support multiple commands in an SSH "exec" channel command.
Quoting section 3.8.3.6 -m: read a remote command or script from a file of PuTTY/Plink manual:
With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain ‘embedded’ servers, such as Cisco routers.
Though you can probably still feed multiple commands to Plink input:
(
echo command 1
echo command 2
echo command 3
echo exit
) | plink -v -ssh user#host -pw password > output.txt
Or you can simply use an input file:
plink -v -ssh user#host -pw password < input.txt > output.txt
Similar question: A way of typing multiple commands in cmd.txt file using PuTTY batch against Cisco
This works without cmd.exe and using files:
function Invoke-PlinkCommandsIOS {
param (
[Parameter(Mandatory=$true)][string] $Host,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential] $Credential,
[Parameter(Mandatory=$true)][string] $Commands,
[Switch] $ConnectOnceToAcceptHostKey = $false
)
$PlinkPath="$PSScriptRoot\plink.exe"
$commands | & "$PSScriptRoot\plink.exe" -ssh -2 -l $Credential.GetNetworkCredential().username -pw "$($Credential.GetNetworkCredential().password)" $Host -batch
}
Usage: dont forget your exit's and terminal length 0 or it will hang
PS C:\> $Command = "terminal lenght 0
>> show running-config
>> exit
>> "
>>
PS C:\> Invoke-PlinkCommandsIOS -Host ace-dc1 -Credential $cred -Commands $Command
....
Sounds like your file 'Out2.txt' has only LF at end of line. Simple way to convert that to CRLF is to use MORE command and redirect output to a new file and then use the new file.
more Out2.txt > Out2CRLF.txt
I ran into the same issue when trying to pull the full list of ACLs on an ASA via plink in powershell.
Essentially, due to the abuse issue referenced in the documentation: https://the.earth.li/~sgtatham/putty/0.72/htmldoc/Chapter3.html#using-cmdline-m, I was getting inconsistent results in pulling the ACLs. Sometimes I would get 0, sometimes only 1 or 2, and sometimes I would get all of them. (I personally, had about a 1 in 5 success rate).
As I would occasionally be successful I used a while loop that would catch the unsuccessful attempts and retry. Just be sure to put some timing on the while loop to prevent it from spamming ssh connections too much.
It is not a good solution, but it worked as a last resort.
Is it possible to write the same output to more than one file in Batch?
My reason for wanting to do this is because I have a large batch script that produces a very detailed log. This is fine as it is, but i want to also output a trimmed back version of the log with a lot less detail in it. The Batch cannot be run multiple times either.
Say for instance I have a simple batch:
Echo This is a Batch Script >> Path\File1 & Path\File2
osql -S%SERVERNAME% -E -d%DATABASENAME% -Q%SQL% >> Path\File1
Appreciate any help.
Maybe you can use the tee command from Unix tools. Downloadable for free from here. Think of it like a "T" that a plumber might put in a pipe to send water two ways.
osql -S%SERVERNAME% -E -d%DATABASENAME% -Q%SQL% | tee file1 file2 file3
Have a look at some examples as I am not entirely sure what your full processing requirement is, see here.
If you want to do some processing on one stream you can do this:
osql -S%SERVERNAME% -E -d%DATABASENAME% -Q%SQL% | tee unfiltered.txt | FINDSTR /v "UglyStuff" > filtered.txt
Second answer, because it is different...
You could use some VBScript, like this to send your osql output to both stdout and stderr and then handle the two separately. This saves you needing to install any Unix tools.
Save this as tee.vbs
REM ############################################################################
REM File: tee.vbs
REM Author: Mark Setchell
REM I don't need any Unix purists to tell me it is not functionally idential to
REM the Unix 'tee' command, please. It does a job - that's all. And I also know
REM there is no error checking. It illustrates a technique.
REM ############################################################################
Set fso = CreateObject ("Scripting.FileSystemObject")
Set stdout = fso.GetStandardStream (1)
Set stderr = fso.GetStandardStream (2)
Do While Not WScript.StdIn.AtEndOfStream
REM Read in next line of input
Line = WScript.StdIn.ReadLine()
stdout.WriteLine(Line)
stderr.WriteLine(Line)
Loop
Then run your osql like this:
osql -S%SERVERNAME% -E -d%DATABASENAME% -Q%SQL% | cscript /nologo tee.vbs 2> unfiltered.txt | FINDSTR "goodstuff" > filtered.txt
Basically, whatever the tee.vbs script writes to stderr gets redirected to wherever 2> points, and whatever tee.vbs writes to stdout goes into the FINDSTR command.
Ideally, you could put your filtering inside the tee.vbs file for maximum flexibility.