none
Show results of CSV import execution of Set command in Powershell

    Question

  • Hello -

    I would like to show the results to the screen (and ideally log file) when running something such as this to hide some mailboxes.

    Import-Csv "C:\hide.csv" | foreach-object {set-remotemailbox -identity $_.ID -HiddenFromAddressListsEnable:$true}

    Running this will execute but just go to command prompt.

    Can it be displayed to screen when running?   Can the action be exported or written out to a log file to show what it did?

    Thanks in advance.

    Wednesday, June 6, 2018 7:33 PM

All replies

  • You can use Start-Transcript.

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-6

    Don't forget to use Stop-Transcript afterward.


    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Wednesday, June 6, 2018 9:31 PM
    Moderator
  • Thanks Ed. But they will only get what I am typing, right? I want to capture what the command is "touching" in the CSV file. Running the command goes right to command prompt so that is all it would capture ?
    Thursday, June 7, 2018 2:05 AM
  • Hi Buzz Saw,

    I don't know why you want to know what the command is "touching". It just read mailboxes from CSV file then set it's value of HiddenFromAddressListsEnable as $true.

    If you want to know the result of executing this command, you can use the script to check this result:

    $Data = @()
    $mailboxes = Import-Csv C:\hide.csv
    
    foreach($mailbox in $mailboxes){
    
    $Data +=Get-RemoteMailbox -Identity $mailbox.Name | select name,HiddenFromAddressListsEnabled
    }
    $Data | Export-Csv C:\hide\result.csv -NoTypeInformation
     

    Note: I noticed that you use Set-RemoteMailbox, do you use a hybrid environment? If you just use an on-premises exchange, you should use Set-Mailbox.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, June 7, 2018 6:19 AM
  • Thanks all.  When I refer to "touching" it is just wanting to see the output (on screen or in text file) to see the progress or the job running. By default it executes the command but just returns to command prompt.   I am hoping to see the progression to be sure the server is not locked up, buffer over run, red errors, etc.

    Yes it is a hybrid.

    I think what may work is starting a transcript as Ed mentioned and adding the ID before the command such as -

    Import-Csv "C:\MP\hide.csv" | foreach {$_.id; set-remotemailbox -identity $_.ID -HiddenFromAddressListsEnable:$true}

    Using the ID variable in front will show me it is running and the transcript will be validation that it ran.

    Thursday, June 7, 2018 2:23 PM
  • I routinely insert Write-Host commands that echo the PowerShell commands I'm interested in.

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Thursday, June 7, 2018 7:03 PM
    Moderator
  • write host didn't work for me as the set command is in the background.   what syntax ?
    Monday, June 11, 2018 12:53 AM
  • Something like this.

    Write-Host -Object "Set-Mailbox -Identity `"Mailbox Name`"" -ForegroundColor Cyan


    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Wednesday, June 13, 2018 6:02 PM
    Moderator
  • Hi Buzz Saw,

    Any update now?
    If the above suggestion helps, please be free to mark it as answer for helping more people.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Sunday, July 1, 2018 7:31 AM