Create a second variable from the first variablbe

130 Views Asked by At

I'm trying to run a command again some mailboxes, after obtaining the mailbox names from a Retention Compliance Policy.

I can export the GUID to a CSV and then call the CSV, but I'm trying to limit my use of CSV's The Below works with a CSV file

$Accounts = Import-Csv 'C:\Temp\MailboxInfoGUID.csv'
ForEach($Account in $Accounts)
{
$Guid = $null
$Guid = @()
$Guid = $Account.ArchiveGuid
Start-ManagedFolderAssistant -Identity $Guid -FullCrawl}

$Users = Get-RetentionCompliancePolicy $LabelPolicyName - 
DistributionDetail | Select - ExpandProperty ExchangeLocation | Select - 
ExpandProperty Name

I'd like to run the command without using a CSV file, but to get the mailbox identity I need to look in the Compliance Policy

How can I use the mailbox names obtained from the policy to then run a crawl on the mailbox

1

There are 1 best solutions below

3
On

If I understood you correct, you would like the following:

  1. Get the mailboxes from Get-RetentionCompliancePolicy.
  2. Iterate through each of those mailboxes grabbing the GUID property.
    • Using Get-Mailbox.
  3. Pass the newly obtained GUID to Start-ManagedFolderAssistant.

Given that's what you're after, the following should work:

(Get-RetentionCompliancePolicy $LabelPolicyName -DistributionDetail).ExchangeLocation.Name | 
    ForEach-Object -Process {
        Start-ManagedFolderAssistant -Identity (Get-Mailbox -Identity $_).ArchiveGuid -FullCrawl
    }

Due keep in mind that I don't have the ExchangePowerShell module installed so I am going off just logic; you may have to adjust the properties.