Search code examples
powershellskype-for-business

Run SefAutil.exe for multiple users and get one File


I am trying to create a script to run daily to get the list of users delegates information, but SefAutil can't accept piping.

Currently, I assign the result to $result for the first user, then export to a text file, and $result2 for the second user, and so on, but I have 20 users, which means 20 text files.

Not sure how to create it so that all output goes to the same text or CSV file with all the users' info. Is this possible?

$result = .\SEFAUtil.exe sip:username.com /server:SFB FDN |  Out-File -FilePath C:\temp\EA\Whatever.TXT
$result1 = .\SEFAUtil.exe sip:jusername.com /server:SFB FDN  |  Out-File -FilePath C:\temp\EA\whatever2.TXT

Solution

  • The following processes multiple users and sends the combined output to a single text file:

    $users = 'username1.com', 'username2.com' # ...
    
    $users | foreach { .\SEFAUtil.exe sip:$_ /server:SFB FDN } > C:\temp\Whatever.TXT
    

    foreach is an alias for the ForEach-Object cmdlet, which processes input objects one by one, with the input object at hand reflected in automatic variable $_.

    Note: > is (effectively) an alias of Out-File.