Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

arrays powershll

Posted on 2012-04-05
3
Medium Priority
?
415 Views
Last Modified: 2012-08-14
I have a script here that I am trying to get to run. It basically goes into the text file and pulls each alias out and runs this against the email alias. The first problem is where to place the alias in the script and the second question is I tried to hard code this in under the command and it still failes.

$userList = Get-Content ("c:\list.txt file")

$MasterArray = @()

foreach ($user in $userList)
      {
      $TempArray = @()
      $TempArray = "" | Select Name, Foldersize, itemsinfolder, prohibitsendquota, UseDatabaseQuotaDefaults
      
      $folderstats = get-mailboxfolderstatistics -id "alias" | Select Name, Foldersize, itemsinfolder
      $MAILQUOTA = get-mailbox -id "alias" | select prohibitsendquota, usedatabasedefaults

      $TempArray.Name = $folderstats.Name
      $TempArray.Foldersize = $folderstats.Name
      $TempArray.itemsinfolder = $folderstats.itemsinfolder      
      $TempArray.prohibitsendquota = $MAILQUOTA.prohibitsendquota
      $TempArray.UseDatabaseQuotaDefaults = $$MAILQUOTA.UseDatabaseQuotaDefaults
      
      $MasterArray += $TempArray
      }

$MasterArray | ft
0
Comment
Question by:techdrive
  • 2
3 Comments
 
LVL 5

Expert Comment

by:kollenh
ID: 37813013
There are multiple things going wrong for you.  You're returning the results of 'get-mailboxfolderstatistics' to a value but it's actually a table that you're returning; $folderstats.Name is an array, not a single value.  You'd need to loop through the items.

Can we step back and have you explain exactly what you're trying to accomplish?  I suspect you want to create a report of mailbox values for a list of users, yes?
0
 

Author Comment

by:techdrive
ID: 37813098
Here is what I am trying to accomplish. I am trying to run two different commands and then pull the results together. I thought an array would accomplish the task. The below commands satisfies what I am looking for but would like for a way to stick the alias in there and have these 5 fields to display.



get-mailbox -id "alias" | select prohibitsendquota, usedatabasedefaults


get-mailboxfolderstatistics -id "alias" | Select Name, Foldersize, itemsinfolder
0
 
LVL 5

Accepted Solution

by:
kollenh earned 2000 total points
ID: 37813370
I understand now; you're basically wanting to join two separate tables.  This should get you on the right track, if it isn't exactly what you want:
Get-Content c:\userlist.txt | foreach {
	$master = @()
	$quota = get-mailbox -id $_ | select ProhibitSendQuota,UseDatabaseQuotaDefaults	
	get-mailboxfolderstatistics -id $_ | select Name,FolderSize,ItemsInFolder | % {
		$temp = @()
		$temp = "" | select Name,FolderSize,ItemsInFolder,ProhibitSendQuota,UseDatabaseQuotaDefaults
		$temp.name = $_.Name
		$temp.FolderSize = $_.FolderSize
		$temp.ItemsInFolder = $_.ItemsInFolder
		$temp.ProhibitSendQuota = $quota.ProhibitSendQuota
		$temp.UseDatabaseQuotaDefaults = $quota.UseDatabaseQuotaDefaults
		$master = $master + $temp
	}
	$master | ft -a
}

Open in new window

0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question