Tips and Tricks

Tips and Tricks
timpringle
PowerShell for Admins

Using Local Functions in a Scriptblock with Existing Code

When you are wanting to run code remotely, it’s common to do this via the use of Invoke-Command (though other options exist, such as through Start-Job for example). The biggest downfall to date i’ve found with remoting is the lack of an option to combine the use of your local functions within a ScriptBlock that has other code in it. As an example, the following is not possible: function Add ($param1, $param2) { $param1 + $param2 } function Multiply($param1,$param2) { $param1 * $param2 } Invoke-Command -ComputerName $env:COMPUTERNAME -ScriptBlock { $addResult = Add $args[0] $args[1] $multiplyResult = Multiply $args[0] $args[1] Write-Output "The result of the addition was : $addResult" Write-Output "The result of the multiplication was : $multiplyResult" } -ArgumentList 3, 2 However, there is a way to achieve this type of operation, and make as many local functions as you want available to be used and combined with other code in your ScriptBlock.

Steve Parankewich
DevOps

Improve Delivery of PowerShell Tools or Version Controlled Files

I am back this week with a quick how-to article on delivering, installing, or launching version controlled files. In the past I ran into problems when having administrators launch my PowerShell tools from a network share. The performance was slow when launching it across the WAN, and the file would often be locked when I tried to replace it with a newer version. I came up with a solution to the problem by using none other than PowerShell.

Steve Parankewich
PowerShell for Admins

Get Last Reboot or Computer Up Time With PowerShell

Hey everyone, hope you had a great 2015 and I am back with I hope to be weekly updates for everyone at PowerShell.org. I wrote up a quick article on how to retrieve the last reboot time or the current up time for any local or remote computer. I also include a function that can be used to query remote computers as well. There may be a situation where you want to determine whether you take action depending on the last reboot time, or you may simply want it to be displayed for debugging or logging purposes.

Steve Parankewich
PowerShell for Admins

Keeping Windows PowerShell Help Up To Date

After a two week hiatus I am back this week with a quick write up on how to automate the updating of PowerShell help. Update-Help should be one of the first things typed in PowerShell on a new workstation build. I jump into the topic and demonstrate how to automate the updating of the help files from the Internet or from a local network share. You can view the full article over at PowerShellBlogger.

Steve Parankewich
PowerShell for Admins

Join Computer to Domain with Specified Computer Name and OU

I addressed a reader requested script for my article this week. PowerShell gives you the ability to add computers to Active Directory right from the command line with the built in PowerShell commandlets. This was introduced with PowerShell version 3 and can be used to automate imaging processes or to prompt an agent for the desired computer name and organizational unit. This is useful since a lot of organizations will use specific OUs for computers according to location or department.

Steve Parankewich
PowerShell for Admins

Find any E-Mail Address or Proxy Address In Active Directory

I am back this week with some more Exchange and Unified Communications goodness. This is another request I see a lot, someone want’s to know where an e-mail address is assigned. This opens up the possibilities of user mailboxes, shared mailboxes, distribution lists, public folders, conference rooms, contacts or resources. I have also seen duplicate e-mail addresses being assigned outside of Exchange causing delivery failures. I take a look at how you can quickly find any e-mail address in your environment along with partial searches of e-mail addresses.

Timothy Warner
PowerShell for Admins

Using Package Management in Windows PowerShell v3

Hey now! The PowerShell team published a preview version of PackageManagement for Windows PowerShell v3 and v4. As it happens, I have a Windows 7 SP1 box running PowerShell v3–why not run a little experiment? `$PSVersionTable.PSVersion Major Minor Build Revision 3 0 -1 -1 `## Preparing the Environment You need .NET Framework 4.5 or later, so take care of that prerequisite before you install the following two assets: Windows Management Framework (WMF) v3 PackageManagement PowerShell Modules Preview I restarted the computer after each installation just to be safe.

Steve Parankewich
PowerShell for Admins

Automate Sip Address and UPN name changes in Lync / Skype for Business

Name changes are a common occurrence in the world of IT and usually the primary concern is the e-mail address. Exchange e-mail address policies will handle this for us but often times the Sip Address and User Principal Name are left behind. I tackle these changes with an automated way of changing the Lync / Skype for Business sip address (also known as sign-in address) and User Principal Name to match the e-mail address.

Steve Parankewich
PowerShell for Admins

Export Subnets from Active Directory Sites and Services

I am back this week with a quick write up on how to export your network subnets from Active Directory Sites and Services. Active Directory Sites and Services subnet assignments are important for healthy replication and for location based services to function properly. The need for this information has come across my desk on several occasions. Even a quick print out would be extremely helpful to keep at your desk. I have included both Windows 7/2008 and Windows 8/2012 methods to ensure everyone is covered.

Steve Parankewich
PowerShell for Admins

Delete Specific E-Mail or E-Mails From All Exchange Mailboxes

Well this is week number two in my quest to post an article once a week and I am back with a common request for Exchange administrators. There are a lot of scenarios that bring up a need to remove an e-mail or e-mails from all mailboxes in your environment. Perhaps there was a disgruntled employee, a virus outbreak, or a reply all to the whole company. We all know that the “Retract” button is best effort (yes I still miss GroupWise for that purpose).