#207874 - 2013-10-07 07:45 PM
Compare Current logged in user against an csv file.
|
jenefa
Fresh Scripter
Registered: 2013-02-01
Posts: 15
Loc: USA
|
Hello, I have need to compare the current logged in user with a csv file which has multiple columns of data. The first column of the CSV file will have the name of the user. 1) How do i get the name of the current logged in user ?
Any pointers or help is greatly appreciated.
|
|
Top
|
|
|
|
#207877 - 2013-10-07 08:43 PM
Re: Compare Current logged in user against an csv file.
[Re: Mart]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
|
If you're looking at remote workstations, you can try something like this:$RemoteHost = 'workstation27'
$ActiveUserID = WMIQuery('UserName', 'Win32_ComputerSystem', $RemoteHost)[0] You can then enumerate the CSV file and determine if $ActiveUserID matches anything.
Some helpful UDFs available here on KORG (latest from my web site resources page): FILEIO() $aFileData = FileIO('file.csv', 'R') will read the entire file into the $aFileData array. $aFileData = FileIO('file.csv, 'W', $aFileData) will write the updated array back to the file and reload the array with the new file content.
CSV() $aRecord = CSV($aFileData[$I]) will take the CSV data from the array and convert it to an array. $aFileData[$I] = CSV($aRecord) converts the array back to proper CSV format.
So - once you have $ActiveUserID - either remote as shown above or local via @USERID, you can use this to match the user ID and get the associated fields.
$ActiveUserID = WMIQuery('UserName', 'Win32_ComputerSystem', $RemoteHost)[0]
$aFileData = FileIO('file.csv', 'R')
For $I = 0 to UBound($aFileData)
$aRecord = CSV($aFileData[$I])
If $aRecord[0] = $ActiveUserID
'Have a match in record ' $I @CRLF
; do stuff here for a matched record...
$I = UBound($aFileData) + 1 ; stop checking records
EndIf
Next Glenn
BTW - Welcome to KORG!
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#207879 - 2013-10-07 10:09 PM
Re: Compare Current logged in user against an csv file.
[Re: Mart]
|
jenefa
Fresh Scripter
Registered: 2013-02-01
Posts: 15
Loc: USA
|
Thank you so much. @USERID solved my issue with getting the current logged in user.
|
|
Top
|
|
|
|
#207884 - 2013-10-08 03:45 PM
Re: Compare Current logged in user against an csv file.
[Re: ShaneEP]
|
jenefa
Fresh Scripter
Registered: 2013-02-01
Posts: 15
Loc: USA
|
Ok, next step for me, i need to check for 2 conditions. 1) If current user is found in 2nd column of the csv file 2) if 1st column of the csv file is user not group.
Is my code on the correct logic
While $found <> "yes" $results = AScan($asharepart2, @USERID) If $results = @USERID IF $aSharegrouporUser[2ndarrayrows] = "user" $found = "yes" EndIF EndIf $2ndArrayrows = $2ndArrayrows + 1 Loop
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|