get-remotemailbox not working in script

Home Forums Messaging Software Exchange 2007 / 2010 / 2013 get-remotemailbox not working in script

This topic contains 2 replies, has 2 voices, and was last updated by Avatar [email protected] 4 months, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #617564

    Hello,
    I’m fairly new to Powershell and trying to process a list of users to report, change and set customattributes. Currently just trying to ready the current value and it’s not working.
    The following script keeps keeps given the wrong variable when I output to screen.
    here’s the Output:
    [PS] C:\scripts\Exchange-Tools>.\ExAttribute-Editor.ps1
    Enter name of the .csv file in C:\Scripts\Exchange-Tools?: 625-ADD.csv
    Enter the value number for the Attribute?: 5
    Enter the Custom Attribute Number or Name?:
    @{-CustomAttribute5=} Result output!!!
    Attribute value for List is: LOUIS BAXTER
    Value for CustomAttrib2 is: -CustomAttribute5
    Result @{-CustomAttribute5=} is currently set for user: LOUIS BAXTER

    Script:
    import-module activedirectory
    $File01 = “C:\Scripts\Exchange-Tools”
    $File02 = (Read-Host “Enter name of the .csv file in C:\Scripts\Exchange-Tools?”)
    $AttribValue = (Read-Host “Enter the value number for the Attribute?”)
    $CustomAttrib = (Read-Host “Enter the Custom Attribute Number or Name?”)
    $CustomAttrib2 = “-CustomAttribute” + $AttribValue.Trim()
    $Path = “$file01\$File02″
    $csv = Get-Content $Path
    foreach($item in $csv)
    {
    $List = $item
    $OutFile = Get-RemoteMailbox -Identity:”$List” |Select $CustomAttrib2
    $out2 = $OutFile
    Write-host $out2 “Result output!!!”
    #$Result = Get-RemoteMailbox “$List” |Select-Object $CustomAttrib2
    #(get-mailbox “$List”).$CustomAttrib2
    Write-Host “Attribute value for List is: ” $List
    Write-Host “Value for CustomAttrib2 is: ” $CustomAttrib2
    #Write-Host “Attribute value for Result is: ” $Result
    #Start-Sleep -s 4
    Write-Output “Result $OutFile is currently set for user: $List”

    Any help you can provide as to why the $OutFile variable is not working is much appreciated!

    Avatar
    wullieb1
    Moderator
    #617686

    Can you explain what you are trying to do with this?

    From what i can see your getting the contents of a CSV file, can you post what these contents are?

    You’re then selecting a custom attribute to be what?

    Start to get some proper commenting in your code so you know what is being done with it and i’d start to look at using write-host for your variables to make sure that the content you are expecting is correct.

    Avatar
    [email protected]
    Participant
    #617691

    Thank you for replying. I was able to figure it out, which was the wrong variable being read.
    Thank you

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.