Solved

arrays powershll

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

The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Find out what you should include to make the best professional email signature for your organization.
In this video we show how to create a User 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 >> Mailb…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

920 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

14 Experts available now in Live!

Get 1:1 Help Now