Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, March 12, 2019 10:30 AM
Hi!
I'm working on a script that is supposed to check a list of <g class="gr_ gr_22 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del" data-gr-id="22" id="22">email-addresses</g> to see if the users still exist or are active and I've run into some difficulties...
This is my script:
$Output = $null
$ImportFile = ".\AllCompanyAddresses.csv"
$ExportFile = ".\Results.csv"
$Adresses = Import-Csv $ImportFile -Delimiter ";"
foreach ($Address in $Adresses)
{
$Enabled = $null
$Type = $null
try
{
Get-Recipient $Address.Email
}
catch
{
$Email = $Address.Email
$Domain = $Address.Domain
$Type = "None"
}
if ($Type -ne "None")
{
$Recipient = Get-Recipient $Address.Email
$Email = $Address.Email
$Domain = $Address.Domain
$Type = $Recipient.RecipientTypeDetails
if ($Type -eq "UserMailbox")
{
$User = Get-ADUser $Recipient.SamAccountName
$Enabled = $User.Enabled
}
}
$Output += New-Object PSObject -Property @{
Email = $Email
Domain = $Domain
Type = $Type
Enabled = $Enabled
}
}
$Output | Export-Csv -Path $ExportFile -Delimiter ";"
I keep getting the following error message:
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\temp\Test\Locate-Addresses.ps1:52 char:2
+ $Output += New-Object PSObject -Property @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*** + CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException***
*** + FullyQualifiedErrorId : MethodNotFound***
Any idea what I'm doing wrong?
Thanks for the help!
Best Regards,
Gerrit
If you think your to small to make a differnce, try going to bed with a mosquito in the room...
All replies (2)
Tuesday, March 12, 2019 11:42 AM ✅Answered
This:
$Output =$null
Should be this:
$Output =@()
\(ツ)_/
Tuesday, March 12, 2019 12:18 PM
Perfect! That did the trick. Thanks <g class="gr_ gr_56 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="56" id="56">alot</g>! :)
If you think your to small to make a differnce, try going to bed with a mosquito in the room...