Should I Use Windows Services or PowerShell for Infrastructure Automation?
Microsoft includes PowerShell in its desktop and server operating systems. It’s a popular command language for IT departments that need to automate tasks. PowerShell is the old Windows DOS command line on steroids. Its programs are called commandlets because they are small programs written in a scripting language similar to .NET and DOS. It uses a customized version of the .NET language, and it has some advantages over Windows services.
Windows services, however, are still the way to go in certain contexts. Here are some tips for choosing the right automation tool for your projects.
Synchronizing Folders and Files
As the network grows, users store their files on different servers throughout the infrastructure. The network could have several file servers, SharePoint servers, application servers, as well as the user’s personal local directories. It’s much more efficient if users store their files in one location, but most network administrators must give up some organization for the sake of user convenience.
PowerShell is the best tool for moving files and folders across different network shares. What takes several recursive functions in C# Windows services takes only a few lines of code in PowerShell. PowerShell can be used to scan several servers and copy folders and files to a specific target directory.
Advantage: PowerShell
Managing User Permissions and Active Directory Policies
Large networks have numerous users and Active Directory (AD) policies. They can be difficult to manage as users change positions or leave the company. Each time users resign, they must have their permissions removed and the account deactivated. This can be tedious for network administrators each day.
PowerShell or Windows services work well to clean up AD policies and permissions. PowerShell works directly with AD, and so does any Windows service. If you have developers within the operations department, they can create a Windows service that scans for deactivated users and cleans up AD. PowerShell can do the same, but you must use the server’s Windows Scheduler to run it each night. Both solutions are effective ways to manage AD changes each day, but PowerShell is a bit more difficult to schedule.
Advantage: Windows services
Synchronize Data with Third-Party Cloud Applications
The cloud is integrated into many systems. For instance, Salesforce is a common cloud application used for customer relation management (CRM). Companies synchronize data between the popular CRM and internal data. The synchronization can happen within minutes, every hour or each night during off-peak hours.
When synchronizing data with off-site services, it’s best to use Windows services. Most of these external cloud services have an API that integrates well with .NET code. Using PowerShell would be much more cumbersome. Windows services can run in intervals that you set within the code without any scheduling. The services run on any Windows server without any interaction from the administrator.
With Windows services, you can extract data from the external cloud application, process it and store it in your own database. You can also send data to the CRM tool. This type of synchronization calls for security since you’re passing data across the Internet. Secure applications are much more efficient in Windows services.
Advantage: Windows services
Upload Data to a SharePoint Server
SharePoint is a Microsoft product used for intranets and document collaboration. Users can create their own sites, upload documents to share with members of their team, and place their own permissions on their site structure.
PowerShell works seamlessly with SharePoint. As a matter of fact, the SharePoint application has its own API that can be used with your PowerShell commandlets. You can use PowerShell to synchronize SharePoint data or upload mass documents to the intranet site. It’s also useful for cleanup and maintenance tasks. For instance, if a user wants to move an intranet site to a new URL, you can automate the task using PowerShell.
Advantage: PowerShell
Data Transformation in SQL Server
Data transformation is the act of pulling data from one database, manipulating the data in some way, and then storing the changed information to a new database. The data “transforms” to a customized format.
For instance, you might have a sales platform that stores subscriptions from web traffic. You pull the data from the public web server database and store it in an internal, secure database. The best platform for this type of operation is Windows services. Windows programs work well with Microsoft SQL Server databases, which is usually the platform used in Windows environments. You don’t need any extra configurations, and the .NET language includes libraries that work directly with the database platform. You could work with PowerShell, but it would be much more inefficient.
Advantage: Windows services
Managing Desktop Services
Network administrators manage hundreds of desktops, and it’s difficult to keep track of the services and programs installed on each machine. With PowerShell, administrators can remotely manage services, programs and desktop configurations. You need administrative permissions to the desktops, but PowerShell can be scheduled to clean up user services and detect any malware running on a machine.
PowerShell works with the Windows API, so it can easily delete, start, and add a service to a desktop. Administrators can even use it to edit local services each time the user logs into the domain. PowerShell commandlets efficiently reduce management time when the administrator needs to deploy or edit services on several remote machines.
Advantage: PowerShell
Audit Network Desktops and Servers
PowerShell can scan a list of computers and audit them. The administrators can get a list of programs installed, services running on the system, and the machine’s information such as CPU or serial number. Windows services can do the same, but you’d need to feed the service a list of computers unless you want it to scan the network. The problem with network scanning is that it can kill your bandwidth.
When you want to audit machines for licenses and program usage, it’s best to use PowerShell.
Advantage: PowerShell
Reboot Frozen Processes
Problematic services on a Windows server sometimes freeze without any warning. These services could be critical to network services. You can write a PowerShell commandlet to automatically reboot the frozen service and avoid any costly downtime.
It only takes one line of code to reboot a service in PowerShell, which makes it more efficient for this administrative task.
Advantage: PowerShell
Conclusion: Windows or PowerShell?
Both of these options have their own benefits. If you need simple network automation, go with PowerShell. If you need more complex services such as data transformation or synchronizing with external APIs, you should use Windows services. Just remember to test your code before you deploy it, because both of these solutions can have a powerful effect on your network.
Updated: January 2019