Hello,
I'm the below works fine but I'm trying to get the results into an array.
Basically Write-Host $row.Item("Username") $row.Item("SizeMB"); gives me what I want on the screen but I need to get that into an array so I can then do what I want with it in PowerShell.
Can anyone point me in the right direction?
$importedusers = Import-CSV c:\PAScripts\UserFiles\PilotRun1.csv
$pausers = @()
foreach ($importeduser in $importedusers)
{
#Write-Host $importeduser.Alias -ForegroundColor Green
$conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=ServerName\Database;Integrated Security=SSPI;Initial Catalog=DatabaseName");
$conn.Open()
$sql = "SELECT SUM(InitialDataSize)/1024/1024 as SizeMB, M.Attribute1 AS UserName
FROM PSTMailbox M
JOIN PSTFile F
ON M.ID = F.PSTMailbox_id
GROUP BY M.Attribute1
ORDER BY SizeMB DESC
"
$cmd = New-Object System.Data.SqlClient.SqlCommand($sql,$conn)
$rdr = $cmd.ExecuteReader()
Foreach($row in $rdr)
{
Write-Host $row.Item("Username") $row.Item("SizeMB");
}
$conn.Close()