I am just getting started in powershell. My goal is to run a script that takes a users input (a device name) and searches the DHCP server and returns just the IP. It then converts the IP into a string and displays it on the console. I did some reseach online and have put together the following script.
$DeviceName = Read-Host "Enter the name of the device"
$PC= $DeviceName + ".companyname.com"
$DHCPServer = 'DHCPserver.com'
$scopes = Get-DhcpServerv4Scope -ComputerName $DHCPServer
foreach ($scope in $scopes){
Get-DhcpServerv4Lease -ScopeId $scope.ScopeID -ComputerName $DHCPServer | Where-Object hostname -eq $PC | Select-Object -Property IPAddress
}
The output is
IPAddress
192.168.x.x
I just can’t figure out how to take that IP(just the numbers) and make it into a string.
I tried putting the output into a variable. I tried exporting to see what it would look like but my txt is blank. I have been reseaching for 3 hours now at my wits end. Any help is welcomed. Thanks in advance.