Reputation: 1
Very green at PowerShell but pretty good with batch and shell scripting. Was going to use curl but really need it to work in PowerShell and was hoping someone has an example to get me started. I need a script to identify one of two types of IoT devices depending on web content. I have some 20k devices that we need to identify the device to be able to manage their passwords in Cyberark and depending on which device will depend on which platform to assign it to.
I want to provide a list of hostnames in a text file, the script will confirm the host is up and responding, then connect to the host URL and pull something unique to identify which type of device and output hostname, device type A or B or hostname, NOT RESPONDING. These IoT devices change depending on which type of battery is attached to them and we have no way of easily identifying which ones.
Upvotes: 0
Views: 700
Reputation: 1462
This is not a complete script, but it can help you to start with..Please refer the following link for using Invoke-webrequest https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.2
$devices = Get-Content C:\PS\ServerNames.txt
$port = "5432" #sample port number
foreach ($device in $devices){
$connection = New-Object System.Net.Sockets.TcpClient($device,$port)
if ($connection.Connected) {
$status = "Success"
#$fromwebrequest = Invoke-WebRequest -uri "https://yoururl" (use Invoke-webrequest instead of curl)
} else {
$status = "Not responding"
}
[pscustomobject][ordered]@{
deviceName = $device
Status = $status
devicetype = $fromwebrequest.deviceType
#addotherparametershere
}
}
Upvotes: 0