Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Errors Outputting to CMD Line Instead of File

$
0
0

I am writing a simple script. In the script I would like to output the errors to a file. I have tried a few different ways to output to a file but each always returns the error to the CMD line.

$URL =  "https://contoso-admin.sharepoint.com"
$Username = "Admin_User@contoso.onmicrosoft.com"
$Password = "Admin_Password"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $Username, $(convertto-securestring $Password -asplaintext -force)
Connect-SPOService -Url $URL -credential $cred

Add-SPOUser -Site "https://contoso.sharepoint.com/sites/Accounting" -LoginName "Admin_User@contoso.onmicrosoft.com" -Group "Accounting Owners"
Add-SPOUser -Site "https://contoso.sharepoint.com/sites/Accounting" -LoginName "Some_Other_Guy@contoso.onmicrosoft.com" -Group "Accounting Owners"
Add-SPOUser -Site "https://contoso.sharepoint.com/sites/Accounting" -LoginName "This one is broken" -Group "Accounting Owners"

I have tried running the script in the following ways:

.\app-spouser.ps1 | tee -filepath C:\add-spouser.csv
.\app-spouser.ps1 >> C:\add-spouser.csv
.\app-spouser.ps1 | -outfile C:\add-spouser.csv -append

But the following error never makes it to the file:

Add-SPOUser : The specified user This one is broken could not be found.
At C:\Users\admin_User\Desktop\app-spouser.ps1:16 char:1
+ Add-SPOUser -Site "https://contoso.sharepoint.com/sites/Accounting" 
-LoginN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : NotSpecified: (:) [Add-SPOUser], ServerException
    + FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerException,Micr 
   osoft.Online.SharePoint.PowerShell.AddSPOUser

How do I get this error into the file?


J Gruber


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>