I am in the process of testing a PowerShell Scritp that assigns 0365 Licences based on Active Directory Group Membership. The Script Connects to the Microsoft Cloud Online
with Cloud Service Account Credentials and then checks the On Prem Active Directory Group and then based on membership assigns a license. When I run the script I don’t
receive any errors or output (its in the cloud) but the script does not perform the intended actions. My question is how can I get or receive output from the script failing
so I can troubleshoot the code’s logic?
Is there a way to generate output fromt the script to sent the errors to the screen or to a local file on the server from which I’m running the script?
You use a combination of write-host and write-output, and | out-file to log script progress to file.
You use try/catch for error detection and handling.
Last time I did a similar task I used the write-log function to write to console and log file in one command (I used ‘log’ as an alias to write-log in some scripts).
Sorry for the late reply. I will try to employ this when I get back in the office. I was trying to write to log per line and it was becomming tedious. Being new to Powershell I wasn’t sure if a single function could write to screen and log simultaneously.
This was very useful in troubleshooting the script. With it, I was able to determine several spelling/syntax errors that led me to more issues. The function worked perfectly.