View same statistics as "Local Area Connection" Status gui from command line - powershell

First time poster here.
I am trying to get the current bandwidth usage for Windows Server 2008R2 via command line. I've tried netstat -e but this gives me very different numbers than the actual bytes that have been transferred.
The stats I'd like to see are the same stats that are shown when you click on "Local Area Connection" (or whatever your active internet connection is listed as) within the "Networking and Sharing Center" gui in Control Panel. Within the gui window that comes up there is the lower "Activity" section. The sent Sent and Received information is what I am trying to get via msdos or powershell.
Thanks to anyone who can lend a hand.

Have you try to use get-Counter.
Here is the line that gives my network card bandwith usage :
get-counter "\\jpbhpp2\interface réseau(intel[r] 82567lm gigabit network connection)\total des octets/s"
But be careful you CAN'T use it like that because counters names are specific to the language of your system.
So you have to adapt it to your computer try :
get-counter
then
get-counter Get-counter -ListSet *

Related

Powershell: Resizing windows by title, not by process id

I'd like to hear your input on this problem:
I have two Citrix Receiver/Workspace sessions active on my desktop and would like to resize the windows by their window title.
I'm aware of the solution to do this via the process id, e. g.
Get-Process | Where-Object { $.Name -eq 'CDVIEWER' -and
$.MainWindowTitle -like 'Window1' } | set-window -X 0 -y 0 -width
3850 -height 1150 -passthru
The problem is that all Citrix Workspace Client windows have the same process id. That leads to the consequence that I can resize only the Citrix Windows that was in the foreground as last.
Is there a way to set the window size by its title and not by its process id?
Thanks,
Thomas
You would need to use native functions imported from user32.dll to access the individual windows - i dont think you can do this from powershell alone. Checkout functions EnumChildWindows, GetWindowText and MoveWindow from above link - those are the building blocks of the functionality you require.
The process would be something like
Get the MainWindowHandle - eg [System.IntPtr] $WindowHandle =(get-process -Name notepad).MainWindowHandle (but for the citrix process).
Use EnumChildWindows with above Handle to locate all its child windows
Iterate through the child windows and use GetWindowText to find the required window (specifically its Handle). Only look at windows with Handles > 0 - there could be multiple other invalid or invisible windows listed.
Use MoveWindow to actually change the position of the window (using Window Handle above).
Id suggest you search each of the above and how to execute from powershell rather than trying to port the API calls to powershell yourself. Using these external functions can be a little tricky, but they are much more powerful.
If you write your own, always use try...catch...finally blocks to make sure you always clean up resources. Powershell cant do it for you with these functions. If you open it, close it, if you allocate memory, free it afterwards etc.
I dont have access to Citrix, but above functions should point you in the right direction.

Having Powershell Autofill command line prompt

There is an old command line tool my company uses to deploy log files to various servers.... whoever wrote it made it very very repetitive.
There is a lot of prompting that happens and I want to automate this process. We have a long term goal of replacing this .exe file down the line but for now automation works for the short term..
Example
./logdeploy.exe
Enter the destination folder:
I would like the powershell script to just automatically enter the folder, since its literally the same folder. because this exe is going to ask for it at least 20 times throughout this process, so copy paste just gets anyoing.
Is this even possible to do?
If there really is no way around simulating interactive user input in order to automate your external program, a solution is possible under the following assumption:
Your external program reads interactive responses from stdin (the standard input stream).
While doing so is typical, it's conceivable that a given program's security-sensitive prompts such as for passwords deliberately accept input from the terminal only, as so to expressly prevent automating responses.
If the first assumption holds, the specific method that must be used to send the response strings via stdin depends on whether the external program clears the keyboard buffer before each prompt.
(a) If it does not, you can simply send all strings in a single operation.
(b) If it does, you need to insert delays between sending the individual strings, so as to ensure that input is only sent when the external program is actively prompting for input.
This approach is inherently brittle, because in the absence of being able to detect when the external program is read to read a prompt response, you have to guess how much time needs to elapse between sending responses - and that time may vary based on many runtime conditions.
It's best to use longer delays for better reliability, which, however, results in increased runtime overall.
Implementation of (a):
As zett42 and Mathias R. Jessen suggest, use the following to send strings C:\foo and somepass 20 times to your external program's stdin stream:
('C:\foo', 'somepass') * 20 | ./logdeploy.exe
Again, this assumes that ./logdeploy.exe buffers keyboard input it receives before it puts up the next prompt.
Implementation of (b):
Note: The following works in PowerShell (Core) 7+ only, because only there is command output being sent to an external program properly streamed (sent line by line, as it becomes available); unfortunately, Windows PowerShell collects all output first.
# PowerShell 7+ only
# Adjust the Start-Sleep intervals as needed.
1..20 | ForEach-Object {
Start-Sleep 1
'C:\foo'
Start-Sleep 2
'somepass'
} | ./logdeploy.exe

How to modify a packet before it is sent to a printer?

I am using old (3 years) label software automatically print barcodes on a production line to a Zebra printer. I just realized and confirmed with their IT that this software, for whatever reason when a print job is triggered, it sends a ^PR6 to the printer, setting the print speed to 6 (and overwriting the 2 I have set). No amount of tooling around with the printers settings or properties we changed were able to override this. IT also told me this product is at end of life and likely no one there will make a patch on it.
It seems like my only solution is to somehow catch this packet before it goes from the server to the printer and remove this ^PR6 from the beginning of the packet so that the print job uses the printers settings. Is there a way that I can do this?
This is all on a Windows Server 2012 system.
Newer printers have a command override command. Send the following command to the printer that you want to ignore the ^PR6:
! U1 setvar "device.command_override.add" "^PR"
More information can be found in the ZPL manual:
https://www.zebra.com/content/dam/zebra/manuals/printers/common/programming/zpl-zbi2-pm-en.pdf

Running two process in one command-line with split-screen

I need to split the command prompt window without making two windows. On one side I need a file to be read and on the other side (split with lines) to be command prompt gathering CPU Usage and RAM Usages. Things I need to know if I can do:
- Gather CPU and RAM Usage from command prompt or batch
- Have two process running side by side in the same window
- Read configuration files in a specific format (such as: server-dir=C:\Users...)
- Have both sides update every second with no glitches in graphics
Could it be done? An example of this would be handle (a minecraft server handler, can be seen here: http://goo.gl/t3741n)

how to find operating system label using command line

like we have %windir% which returns the C;\windows , do we have any command that returns only the operating system drive letter ('C') ?
I tried the command "label" but it returns more than the label info..
WMIC.exe allows you to make WMI queries from the command line.
wmic os get systemdrive
will tell you the same thing as %SystemDrive%, though you can also use it for InstallDate, SystemDirectory (i.e. %WINDIR%\System32, though I don't recall ever having seen a machine with a different name for that directory), LastBootupTime, etc.
The output isn't necessarily easy to parse from a script, but if you just want to see the info, it's very useful.
On windows, try these:
1. %SystemDrive%
2. %HOMEDRIVE%
The first gives you the drive letter that holds your system files, the second gives you drive letter that holds your documents.