How would I add "overall provisioning status" to the output of this script?

# The Output will be written to this file in the current working directory 
$LogFile = ($(get-date -Format yyyy-MM-dd) + "-litholdRESULTS.csv")

# Run Script to Set Holds
$MBXs = Get-Mailbox -ResultSize 50 -Filter {LitigationHoldEnabled -eq "False"}
$(Foreach ($Mbx in $MBXs){
Try {
$Mbx | Set-Mailbox -LitigationHoldEnabled $true -ea STOP
New-Object PSobject -Property @{
       Mailbox = $Mbx.DisplayName
       Status = "Success"
}
}Catch{
New-Object PSobject -Property @{
       Mailbox = $Mbx.DisplayName
       Status = $_.Exception.Message
}
}
})| Export-Csv $LogFile -nti 

Open in new window


*Credit to Subsun for the original script
LVL 9
K BAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vasil Michev (MVP)Commented:
OverallProvisioningStatus is attribute for Get-MsolUser, so you need to make sure you are connected to WAAD as well. Then, you can do something like this:

OverallProvisioningStatus = (Get-MsolUser -UserPrincipalName $mbx.UserPrincipalName).OverallProvisioningStatus

Open in new window


OverallProvisioningStatus is not that reliable imo, you can use SKUAssigned instead. Well, depends on what you are actually trying to achieve :)
K BAuthor Commented:
Thank you Vasil...

So would it look like this?

# The Output will be written to this file in the current working directory 
$LogFile = ($(get-date -Format yyyy-MM-dd) + "-litholdRESULTS.csv")

# Run Script to Set Holds
$MBXs = Get-Mailbox -ResultSize 50 -Filter {LitigationHoldEnabled -eq "False"}
$(Foreach ($Mbx in $MBXs){
Try {
$Mbx | Set-Mailbox -LitigationHoldEnabled $true -ea STOP
New-Object PSobject -Property @{
       Mailbox = $Mbx.DisplayName
       Status = "Success"
}
}Catch{
New-Object PSobject -Property @{
       Mailbox = $Mbx.DisplayName
       Status = $_.Exception.Message

OverallProvisioningStatus = (Get-MsolUser -UserPrincipalName $mbx.UserPrincipalName).OverallProvisioningStatus
}
}
})| Export-Csv $LogFile -nti  

Open in new window

Vasil Michev (MVP)Commented:
Well you probably want it both for the Try and Catch scenarios :)

# The Output will be written to this file in the current working directory 
$LogFile = ($(get-date -Format yyyy-MM-dd) + "-litholdRESULTS.csv")

# Run Script to Set Holds
$MBXs = Get-Mailbox -ResultSize 50 -Filter {LitigationHoldEnabled -eq "False"}
$(Foreach ($Mbx in $MBXs){
Try {
$Mbx | Set-Mailbox -LitigationHoldEnabled $true -ea STOP
New-Object PSobject -Property @{
       Mailbox = $Mbx.DisplayName
       Status = "Success"
       OverallProvisioningStatus = (Get-MsolUser -UserPrincipalName $mbx.UserPrincipalName).OverallProvisioningStatus
}
}Catch{
New-Object PSobject -Property @{
       Mailbox = $Mbx.DisplayName
       Status = $_.Exception.Message
       OverallProvisioningStatus = (Get-MsolUser -UserPrincipalName $mbx.UserPrincipalName).OverallProvisioningStatus
}
}
})| Export-Csv $LogFile -nti  

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
K BAuthor Commented:
Vasil you rock!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.