Thanks.
I would expect that that (or something similar) would work just at face value. Thus far no success...
I have been doing some testing as well.
I have a HP Office Jet Pro 9015 printer on my network with a Static IP address 192.168.1.102 (subnet 255.255.255.0)
Here is my hosts file with the substitution macro at the end.
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
#Testing Substitution Macro
192.168.1.102 HPOfficeJet
#End of Test
= = = = Ping results via elevated PS>
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements!
https://aka.ms/PSWindows
PS C:\WINDOWS\system32> ping 192.168.1.102
Pinging 192.168.1.102 with 32 bytes of data:
Reply from 192.168.1.102: bytes=32 time<1ms TTL=64
Reply from 192.168.1.102: bytes=32 time=1ms TTL=64
Reply from 192.168.1.102: bytes=32 time=1ms TTL=64
Reply from 192.168.1.102: bytes=32 time=1ms TTL=64
Ping statistics for 192.168.1.102:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms
PS C:\WINDOWS\system32> ping HPOfficeJet
Ping request could not find host HPOfficeJet. Please check the name and try again.
PS C:\WINDOWS\system32>
= = = =
I have tried a couple of variations in hosts with the same "could not find" results.
For examle using/including "alias" as in Post 15.
Only posting the preceeding "code" in hopes that there may be some error of omission or commision on my part.
I have found a couple of PS scripts that are much more involved but fail with various errors - TBD.
Possibly a function could be made to work.
The requirement being to make my computer (or any computer on my network) that when given a name then associate that name with 192.168.1.102 and go forward with ping to 192.168.1.102 when "ping HPOfficeJet" is used. Or do whatever if/when "HPOfficeJet" is appropriately used.
Printer mac may be needed somewhere ???
My next experiment is going to be with Environmental Variables.
Run
Get-ChildItem Env:
Maybe (thinking out of the box a bit) create an Environment variable "HPOfficeJet" value "192.168.1.102"
And will climb back in if I fall out as tends to happen...
No harm in thinking out loud and sharing.