Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Query SQL DB

$
0
0

I want to query a SCCM DB to find out all the machines a user has logged into.   I have this working using SQL but I wanted to write this in PowerShell so I can run it without having to log into my SQL server or my SCCM server.  

#  This code works fine.  I'm using the Quest AD Plugins.  


$UserName = Read-Host 'Please enter the user name'
Get-QADUser -ANR $UserName | Select -ExpandProperty sAMAccountName

-- This SQL code works as well.   It will show me every computer the user has logged on it.  

select
rs.Name0  AS [PC Name],
ru.User_Name0  AS [Logon Name],
Full_User_Name0 AS [Full Name]

from v_R_System rs 
LEFT JOIN v_R_User ru on rs.User_Name0 = ru.User_Name0

where ru.User_Name0 LIKE 'MrUserName'

.

But how do I query these exact same SQL Views using PowerShell?  


mqh7


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>