Here's a recap of what you may have missed in our webcast last Thursday where we talked about using Regular Expressions in PowerShell.
Last week on PDQ Live we went over some of the uses for RegEx and how it can help you clean up your data for easier use in scripts.
For some RegEx resources see below or check out part of the webcast by clicking here.
1.What is a good resource for troubleshooting PowerShell scripts?
Visual Studio code is a great resource as it uses PSScriptAnalyzer. PowerShell subreddit, PowerShell Slack channel, you can even post it to our forums and we will help (make sure you sanitize the script first).
2.What are some of the best formatting practices you use when writing functions?
In the Powershell ISE you can right click select ‘Start Snippets’ and use the pre-built snippets. These will provide templates for common functions.
3.Is there a way to run a PowerShell script and have the results emailed? If so is there a way to only email scripts that return a result.
There is a built-in cmdlet called 'Send-MailMessage.' You can use this to send the result of the script. To prevent it from sending empty emails you could compare the result of your script to $null before sending the email.
4.How would you get user info from Active Directory - like getting their phone numbers?
You can use the Get-ADUser to pull pretty much any info you need from the user object. Make sure you specify the property you want using the -Property flag.
5.I am uninstalling a program with PowerShell script and PDQ Deploy, but the PowerShell script hangs. Is there a way to end the PowerShell script and move on to the next step? Perhaps a close command… of some sort?
It really depends on why the script is hanging. A common issue is forgetting to add the silent parameters to the uninstall string, if this happens it will pop-up a window expecting you to interact with the uninstall window. If you have a specific issue feel free to hit up [email protected]