Author Posts

August 11, 2013 at 6:33 pm

Hello

I've been working on a script which gets Enterprise vault environment from SQL and merges it with Exchange data and finally generate a neat csv using both data sources. In near future, will add some more features to it but for now, that's what it does in nutshell.

However, I am unable to use "foreach" loop on data collected from SQL servers and pass it for processing and merge with exchange data, I am not sure where I went wrong.

In attached txt file, you can find the two functions I am using. First function is working as expected (Function GetEnterpriseVaultData), if I export csv files directly from there, no issues. It returns SQL tables in form of string array.

However in second function (Function GetMailboxData), where I use foreach ($Archive in $EnterpriseVaultData), the $Archive takes complete $EnterpriseVaultData and basically remaining function doesn't works since it is expecting singular value.

If you guys can take a look please and point me in right direction, will appreciate a lot.

Thanks in Advance.

August 11, 2013 at 7:00 pm

It looks like $EnterpriseVaultData will contain a DataTable object, not an array. I think what you're actually trying to accomplish is something like this:

foreach ($Archive in $EnterpriseVaultData.Rows) {
    # ...
}

Not sure if you'll be able to access columns in those rows as if they were properties of the DataRow. It's possible; PowerShell does that in a lot of other places (XML, WMI, etc), but if not, you'll need to use $Archive.Item('ColumnName')

August 11, 2013 at 7:58 pm

Thanks Dave, will give it a shot. Meanwhile, attached is property set for $EnterpriseVaultData variable.