Get IP ADDRESS from MAC ADDRESS for Printers - powershell

Is it possible to get IP from MAC Address of printer.
I have got MAC address and want to know what IP is assigned to it via DHCP server.
I tried the below query and it does give me all the IP address in scope but I need to be able to search for the one I am looking for.
netsh dhcp server \\DHCP server scope 10.65.22.0 show clients 1
I tried using Where {$_.uniqueID -like "002128903a09"} but it does not seems to like it.
Thanks

So netsh is an external application, and will return a bunch of text, but not objects, so you can't check a property (like $_.uniqueID) using a Where statement. You have two options here, you can search for the line of text that has your MAC and consume the whole line, or you can parse the text and convert it to objects. I am not familiar with the results that get spit out when you run that command, so if you want to give a sample of that (update your question to include it, don't put it in a comment), I can probably help you parse the text into objects, or just search it for a MAC address.
Or, one option would be to pipe the command into the Select-String cmdlet, and have that search for your MAC address.
$MACAddr = ("002128903a09" -split "(..)"|?{$_}) -join "-"
netsh dhcp server \\DHCP server scope 10.65.22.0 show clients 1 | Select-String -SimpleMatch $MACAddr
I believe that will at least find the line that has your MAC, and you can get the IP from there.
Edit: Updated with MAC Address formatting corrected, thanks to #JanChrbolka for helping me with the correct format!

Related

Updating MAC Address in a DHCP reservation removes other variables

i have an odd issue for when i run this command:
Set-DhcpServerv4Reservation -computer name -ip 1.1.1.1 -clientid macaddress
it removes a few other variables, such as "root path". when I run get-dhcpreservation on an IP that has all of its variables set, "root path" is not something it returns, and it is not something that I can set with powershell -- plus, i'd rather it not be removed.
are there any other methods to update a dhcp reservations mac address?
after fiddling around with Set-DhcpServerv4Reservation there is really no way to set the mac address with that command without deleting option values that are set, such as iscsi targets. there is also seemingl
the fix was using Get-DhcpServerv4OptionValue to store what would be deleted as a variable, use set-dhcpserver4reservation to set the MAC address, then use set-dhcpserverv4optionvalue to add back what was deleted.
not the most ideal solution but i was successfully able to update the mac address while preserving everything that the command was deleting.

Printing ESC/POS (raw) using windows powershell

I am trying to print receipts on my Epson TM20ii using ESC/POS commands, sending them to the printer with out-printer' I have tried using both the epson driver and a generic text driver. My problem is that the printer is printing the command instead of executing it. See example
"LF" | out-printer -name epson
LF is the command for the printer to feed one line, instead of doing so the printer is printing the characters LF
I figured it out.
as some users commented, the commands are referring to the actual ASCII characters.
this however did not fully solve the problem as for some reason the powershell out-print command was sending the info to the printer in a way that the printer did not understand to be meant to be interpreted as esc-pos commands. The easiest solution that i found so far is a command line utility called RawPrint.exe which can be found here. The tool is very straight forward and i highly recommend it.

How to change & verify hostname in windows server 2012 (AWS EC2)

I am using Windows Server 2012-R2 (amazon ec2) machine.
and I want to change and verify hostname in it. I checked on net and found hostname command. But when I run hostname or hostname -i command I get following error..
sethostname: Use the Network Control Panel Applet to set hostname.
hostname -s is not supported.
I further googled this problem and apparently this command is not usable on windows 2012-r2 servers. Is there any alternative or workaround command that can do the job for me??
On windows the computer name is also often referred to as hostname. However this creates some confusion. Some people use the term hostname to refer to the leftmost part of domain name which can only be set on a DNS server. However another meaning of a hostname is just an arbitrary label assigned to a machine on a computer network, and this can be directly changed on the specific machine.
There are several ways to change the computer name from the command line on windows 2012:
Method 1. Open cmd and type:
SCONFIG and you will get selection menu where #2 says Computer Name:
Method 2. From cmd type:
netdom renamecomputer %computername% /newname:<NewName> /reboot:0
Method 3. From the PowerShell console:
netdom renamecomputer $env:computername /newname:<NewName> /reboot:0
To verify the name form cmd type:
nbtstat -A xxx.xxx.xxx.xxx (where x is the ip address)
Another way to verify the name form cmd just type "hostname" without any parameters:
hostname

Executing cmd command "change port" from a variable

I'm having an issue with a pretty simple script and I think I'm just missing something fundamental. It checks to see if a certain device is plugged into a COM port, and if it it finds it, remaps it to COM1.
change port com1 /d
$ComNum = (change port) -match 'COM.+19h2kp0' -replace '^(COM\d+).+','$1'
$changeport = ("change port COM1=" + $ComNum)
$changeport
It seems to work perfectly, the output I get is
change port COM1=COM4
The problem is that even though the output looks perfect, the command doesn't actually run. Is there a Powershell limitation to executing a cmd command from variable?
Thank you in advance!
You are simply printing a variable (returning it, actually). You need to invoke it using Invoke-Expression, Invoke-Command or simply use the & aka Call operator.

How to retrieve the CNAME on Windows?

I want to know if there is an existing command or script to retrieve the Canonical Name Record (CNAME) for a given computer or server. I would like to use this via CMD/Powershell I don't mind if such command or script uses the Windows Registry Editor (regedit).
The hostname program/command should give you the DNS name of the local machine, whereas the shell command echo %COMPUTERNAME% should show you the NetBIOS name (which might be different).