Solved

arrays powershll

Posted on 2012-04-05
3
404 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Too many email signature changes to deal with?

Are you constantly being asked to update your organization's email signatures? Do they take up too much of your time? Wouldn't you love to be able to manage all signatures from one central location, easily design them and deploy them quickly to users. Well, you can!

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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…
This video discusses moving either the default database or any database to a new volume.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now