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

SQL Query help

$
0
0
Guys,
 
I have the following query which runs successfully inside SQL Management Studio.  I would like to be able to use powershell to loop through a list of users and run this query per user (using system.data.sqlclient objects).
 
SELECT A.ArchiveName,
  COUNT(S.IdTransaction) "Num. Items Archived",
  SUM(S.ItemSize)/1024 "Archived Items Size (MB)",
  SUM(SP.OriginalSize)/1024/1024 "Original Email Size (MB)"
FROM EnterpriseVaultDirectory.dbo.Archive A,
  EnterpriseVaultDirectory.dbo.Root R,
  yourVaultStoreDB.dbo.ArchivePoint AP,
  yourVaultStoreDB.dbo.Saveset S,
  yourVaultStoreDB.dbo.SavesetProperty SP
WHERE S.SavesetIdentity = SP.SavesetIdentity
  AND S.ArchivePointIdentity = AP.ArchivePointIdentity
  AND AP.ArchivePointId = R.VaultEntryId
  AND R.RootIdentity = A.RootIdentity
  AND A.ArchiveName = 'your User'
GROUP BY A.ArchiveName

I have used powershell to connect to sql before - but only simple queries ie single databases.

Any help greatly appreciated.


Viewing all articles
Browse latest Browse all 6937

Latest Images

Trending Articles



Latest Images