Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Trying to check the current logged on user against a CSV, to find value of row

$
0
0

Hi,

Real newb, sorry...

I'm trying to fetch data out of a *.csv file. The data it will look for is the currently

logged on user (well that is easy $env:username), but the *.csv has two columns

where the usernames are stored (in no sorted order). The other column contains

an e-mailserver adress, which is what I'm after.

So to speak, check the csv file for the logged on user, write out the corresponding

servervalue on that same row.

 

$User = @()
$Server = @()
Import-Csv .\users.csv -Delimiter ";"
   ForEach-Object {
        $User += $_.uid
        $Server += $_.kedlnmailserver
   }
$UserName = $env:username
if ($User -contains $UserName) {
Write-Host "Gotcha!"
$Where = [array]::IndexOf($User, $UserName)
Write-Host "Server:" $User[$Where]
}

 

The *.csv file looks like this:

uid;kedlnmailserver

123456;mailserver1

654321;mailserver2

111000;mailserver3

 

The exported *.csv file is from our user catalog and is exported daily,

the purpose of this script is to make it easier to collect the mailserver

for that particular user (since we have to many servers I'm afraid).

 

Cheers,

 

//Markus


Viewing all articles
Browse latest Browse all 6937

Latest Images

Trending Articles



Latest Images