none
Powershell script to fetch info of all outlook accounts in user's machine. RRS feed

  • General discussion

  • We have developed a script to obtain the information about all the outlook accounts, username and computer name and we are going to export the results in csv file on network location. The script is ready but output for multiple outlook accounts is coming in the same cell, but we want output should be in different row.

    I am unable to share the links or screenshots.

    Thursday, October 12, 2017 9:06 AM

All replies

  • Without a script we cannot help you.


    \_(ツ)_/

    Thursday, October 12, 2017 9:14 AM
  • Thanks for getting back to me. shall I PM you or post the script here?
    Thursday, October 12, 2017 12:09 PM
  • any update on this?
    Tuesday, October 24, 2017 3:27 PM
  • You have to post your script.


    \_(ツ)_/

    Tuesday, October 24, 2017 5:06 PM
  • $o16path=Test-Path "hklm:\Software\Microsoft\Office\16.0\Common\FilesPaths"
    $Computer = $env:computername
    $a = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
    Write-Host "Username:"$a
    $LogFile = "\\Network location\OutlookAccountsTesting.csv"
    $results = @()

    If ($o16path -eq $false)
    {
    $prop=Get-ItemProperty "hkcu:\Software\Microsoft\Office\15.0\Outlook\Profiles\*\9375CFF0413111d3B88A00104B2A6676\*"
    $Formatenumerationlimit =-1
    Foreach ($value in $prop) {
    Get-ItemProperty $value.pspath | foreach {
    $Data = $value."Account Name"
    $array = @($data)
    $string = [System.Text.Encoding]::UTF8.Getstring($array)
    If (($string -ne 'Outlook Address Book') -and ($string -ne 'Outlook Data File'))
    {$string

    }
    }
    }
    }

    Else

    {
    $String = Get-ItemProperty "hkcu:\Software\Microsoft\Office\16.0\Outlook\Profiles\*\9375CFF0413111d3B88A00104B2A6676\*" | Ft "Account Name"
    $string | % { $_.name }
    If (($string -ne 'Outlook Address Book') -and ($string -ne 'Outlook Data File'))
    { $string




    $props = @{
        ComputerName=$computer
        UserName=$a
        Outlook= (@($string) | out-string).trim()
        }
    $results += New-Object psobject -Property $props


    $results | select-object Outlook,ComputerName,Username | Export-Csv -NoTypeInformation -path $LogFile -Append
    Thursday, October 26, 2017 11:17 AM
  • You are putting everything into a single column:

     Outlook      = (@($string) | out-string).trim()

    if you want information in separate cells(columns) you have to create separate columns for the items.


    \_(ツ)_/

    Thursday, October 26, 2017 12:30 PM
  • Thanks for the reply!! What should I modify in the script to get the proper output? It also should add an output from another machine on next cell or column.
    Friday, October 27, 2017 12:00 PM
  • Not sure what the question means.  You need to understand how a CSV works, how to create objects and then how to export them.

    If you start by posting your code correctly using the code posting tool then you would begin to see how the code works.  

    Also note that there can be multiple profile paths.


    \_(ツ)_/


    • Edited by jrv Friday, October 27, 2017 12:11 PM
    Friday, October 27, 2017 12:06 PM
  • This is all you need to do:

    Get-ItemProperty "hkcu:\Software\Microsoft\Office\16.0\Outlook\Profiles\*\9375CFF0413111d3B88A00104B2A6676\*" |
    	Where{$_.'Account Name' -notmatch 'Outlook Address Book|Outlook Data File'} |
    	Select @{n= 'ComputerName';e={$env:COMPUTERNAME}},@{n= 'UserName';e={$env:USERNAME}}, 'Account Name'
    
    


    \_(ツ)_/

    Friday, October 27, 2017 12:58 PM
  • This is how to handle this kind of situation:

    $logFile = '\\Network location\OutlookAccountsTesting.csv'
    
    If (Test-Path 'hkcu:\Software\Microsoft\Office\15.0\Outlook\Profiles') {
    	$regPath = 'hkcu:\Software\Microsoft\Office\15.0\Outlook\Profiles\*\9375CFF0413111d3B88A00104B2A6676\*'
    }elseif(Test-Path 'hkcu:\Software\Microsoft\Office\16.0\Outlook\Profiles'){
    	$regPath = 'hkcu:\Software\Microsoft\Office\16.0\Outlook\Profiles\*\9375CFF0413111d3B88A00104B2A6676\*'
    }else{
    	Write-Host 'Outlook not found'
    	exit
    }
    
    Get-ItemProperty  $regPath |
    	Where{$_.'Account Name' -notmatch 'Outlook Address Book|Outlook Data File'} |
    	Select @{n= 'ComputerName';e={$env:COMPUTERNAME}},@{n= 'UserName';e={$env:USERNAME}}, 'Account Name' |
    	Export-Csv $logFile
    


    \_(ツ)_/

    Friday, October 27, 2017 1:05 PM
  • Thank you so much. This really helps a lot. I added "-append" at last (Export-Csv $logFile -Append) as we need to run this script on multiple machines and collect the data in single file. This is working fine in powershell 4.0 but not working properly in PS 3.0. Getting output like "

    System.Byte[]".

     Any thoughts?

    Regards.


    Monday, October 30, 2017 12:25 PM
  • Why are you using append?  The code has no need of it.

    \_(ツ)_/

    Monday, October 30, 2017 1:19 PM
  • I need to run this script on multiple machines and store the result only in one csv file. If I run a script on 1st machine and then run it on 2nd machine, it overrides the output of 1st machine, hence i am using append to store the output in next row. Hope that makes sense!!
    Tuesday, October 31, 2017 9:22 AM