Custom Variable - Current Logged On User (for Dynamic Collections)

Hey @all,

I would like to use the current logged on user as a variable for Dynamic Collections.

A reason is that I would like to check if the current logged on user is part of the local administrators group on his logged on computer..

Do anyone know if this is somehow possible?

I am thankful for all answers.

Greeting,

Mazl

0

Comments

6 comments
Date Votes
  • %username% should give you the current user.

    0
  • $env:username if using PowerShell

    0
  • Sorry I think I described my problem completly wrong. I would like to create a "Dynamic collection" and use the current logged on user of the computer as a variable.

    The reason is that I want to create e.g. a Dynamic Collection that gives me all the computers where the logged on user is part of the local Administrators group.

    0
  • Sorry I think I described my problem completly wrong. I would like to create a "Dynamic collection" and use the current logged on user of the computer as a variable.

    The reason is that I want to create e.g. a Dynamic Collection that gives me all the computers where the logged on user is part of the local Administrators group.

    0
  • The best way I can think of doing this is having a login script GPO, that runs a PowerShell script. This PowerShell script checks the current user against the members of the local admins and then imports that data into a custom field for that PC in Inventory.

    If I get some time spare today, I'll have a play with PowerShell and see if I can get something working.

    0
  • This works. It's probably not the best way of doing this.

    $user = "$env:USERNAME";
    $group = "Administrators";
    $groupObj =[ADSI]"WinNT://./$group,group" 
    $membersObj = @($groupObj.psbase.Invoke("Members")) 
    
    $members = ($membersObj | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)})
    
    $ErrorActionPreference = 'Continue'
    
    If ($members -contains $user) {
    $exists = $true
    } Else {
    $exists = $false
    }
    
    Write-Host "$exists"
    
    $computer = $env:COMPUTERNAME
    
    $customfieldname = "Admin?"
    $Customfieldtype = "String"
    
     $computerlist = @("ComputerName,$customfieldname")
    
     $computer | ForEach-Object {
    
    $computerlist += "$_,$exists"
    
    }
    
    pdqinventory createcustomfield -name $customfieldname -type $customfieldtype
    $tempfile = New-TemporaryFile
    $computerlist | out-file $tempfile
    
    pdqinventory importcustomfields -filename $tempfile -computercolumn "ComputerName" -customfields "$Customfieldname=$customfieldname" -allowoverwrite
    
    0

Please sign in to leave a comment.

Didn't find what you were looking for?

New post