Solved

arrays powershll

Posted on 2012-04-05
3
408 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 500 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
In this video we show how to create a Shared Mailbox 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 Recipients >> Sha…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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