I have read Read a Csv file with powershell and capture corresponding data and have been able to put together some code but it is not giving me what I wanted it to, I am trying to get it to read a CSV, find a server in column 1 and open the ip address in column 2 in Internet explorer.
function Open-RAC
{
param
(
[Parameter(Mandatory = $true)]
[string]$ComputerName
)
$ServerName = @()
$IMM = @()
Import-Csv C:\Scripts\ComputerList\IMMs.CSV |
ForEach-Object {
$ServerName += $_.ServerName
$IMM += $_.IMM
}
$inputNumber = $ComputerName#Read-Host -Prompt "Short Server Name"
if ($ServerName -contains $inputNumber)
{
Write-Host "DRAC Exist"
Write-Host "Servername : $inputNumber"
$Where = [array]::IndexOf($ServerName, $inputNumber)
Write-Host "Where : $Where"
Write-Host "DRAC IP Address: " $IMM[$Where]
$URL = $IMM[$Where]
Write-Host "$URL"
$IE = new-object -com internetexplorer.application
$IE.navigate2("http:\\$URL")
$IE.visible = $true
}
Else
{
Write-Host " That server does not have a DRAC or you mistyped the server name"
}
however this is not giving my the correct IP address back but whatever the last one in the CSV is.
Any help is appreciated.