Get process owner from AD
<p>I am using Powershell on Windows Server 2008 R2 and I need any regular user get owner of the process with name and surname from AD.</p>

<p>Here's script wrote with help of <strong>Mathias R. Jessen</strong></p>

<pre><code> Import-Module ActiveDirectory
$ProcessWithOwners = Get-WmiObject Win32_Process -Filter 'Name LIKE "vr[0-9]%"' |Select *,@{Name="Owner";Expression={$_.GetOwner().User}}
 foreach($Process in $ProcessWithOwners)
 {
    $Username = $Process.Owner 
    $ADUser = Get-ADUser -Filter "SamAccountName -eq '$Username'" -properties *
    $a = new-object -comobject wscript.shell
    $b = $a.popup(“Process name $($Process.Name) is run by user $($ADUser.DisplayName)“,0,“Warning”,1)
 }
</code></pre>

<p>But regular user can't get access to process's owner.</p>

<p>Is there any way to solve it?</p>

<p><strong>* Final Update *</strong></p>

<p>For running this script as regular user I made some changes:</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>Import-Module ActiveDirectory
 
Add-Type -Name win -MemberDefinition '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);' -Namespace native
[native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle,0)
 
$ConsProcess = Get-WmiObject Win32_Process -Filter 'Name LIKE "vr[0-9]%"' | Select *,@{Name="Owner";Expression={$_.GetOwner().User}}
 
if ($ConsProcess -ne $null) {
 foreach($Process in $ConsProcess)
 {

$QueryProcess = query process $Process.ProcessName
$Id = ($QueryProcess[1] -replace ' +',' ').Trim().Split(' ')[2]
$QueryUser = query session $Id
$User = ($QueryUser[1] -replace ' +',' ').Trim().Split(' ')[1]
$ADUser = (Get-ADUser -Identity $User -Properties *).DisplayName

$a = new-object -comobject wscript.shell
$b = $a.popup(“Консультант запущен с именем $($Process.Name) пользователем $($ADUser)“,0,“Внимание”,1)
 }
}

else
{
&amp; 'D:\consultantplus\cons.exe' /adm /inet
}</code></pre>
</div>
</div>
</p>