---
title: "Integrate Git & Jenkins for Scheduled PowerShell Scripts"
description: "Integrate Git version control with Jenkins to set up and schedule PowerShell scripts to run at predefined schedules."
canonical: "https://adamtheautomator.com/powershell-jenkins/"
---

# Integrate Git & Jenkins for Scheduled PowerShell Scripts

> Integrate Git version control with Jenkins to set up and schedule PowerShell scripts to run at predefined schedules.

Source: https://adamtheautomator.com/powershell-jenkins/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Integrate Git & Jenkins for Scheduled PowerShell Scripts](https://adamtheautomator.com/wp-content/uploads/2019/10/jenkins.png)

# Integrate Git & Jenkins for Scheduled PowerShell Scripts

[![](https://secure.gravatar.com/avatar/976e521b05050a45314932192c1c3f41bd98a1eac41ceaaa5af2160a9cf8bb68?s=192&d=mm&r=g)Phillip Marshall](https://adamtheautomator.com/author/phillip/)17 October 20196 min. read

Categories: [DevOps](/category/devops/)

Tags:[Jenkins](/tag/jenkins/)[PowerShell](/tag/powershell/)

Table of Contents

*   [PowerShell Script Sprawl: This Isn’t Working](#powershell-script-sprawl-this-isn-t-working)
*   [Why Jenkins?](#why-jenkins)
*   [Better Control](#better-control)
*   [Easy Scheduling](#easy-scheduling)
*   [Version Control](#version-control)
*   [Consolidated Logging](#consolidated-logging)
*   [Prerequisites/Requirements](#prerequisites-requirements)
*   [Installing the PowerShell Plugin](#installing-the-powershell-plugin)
*   [Creating a Job](#creating-a-job)
*   [Adding the Windows PowerShell Build Step](#adding-the-windows-powershell-build-step)
*   [Executing the PowerShell Script](#executing-the-powershell-script)
*   [Schedules and Triggers](#schedules-and-triggers)
*   [Creating a Schedule](#creating-a-schedule)
*   [Further Reading](#further-reading)

If you and your team have way too many PowerShell scripts lying around running who knows where, this article is for you. In this article, you’re going to learn how to set up the popular [Jenkins automation server](https://jenkins.io/doc/pipeline/tour/getting-started/) to manage and execute PowerShell scripts!

Not a reader? Watch this related video tutorial!

**_Not seeing the video? Make sure your ad blocker is disabled._**

You’ll learn how to integrate Git version control with Jenkins to then set up and schedule [PowerShell](https://adamtheautomator.com/tag/powershell/) scripts to run at predefined schedules.

## PowerShell Script Sprawl: This Isn’t Working

As an automation engineer, one of the main challenges my team and I had to overcome was scheduled PowerShell script sprawl. I found dozens of PowerShell scripts being scheduled and run from many different places.

Each engineer, or team of engineers, had their own server that they scheduled things on. Each type of script was executed on the server that ran that service.

*   A domain controller ran all of the Active Directory scripts.
*   An Exchange server ran all of the Exchange scripts.
*   A member server ran all networking team scripts.
*   A member server ran all of the database scripts for the DBAs.
*   A member server ran all of the security team’s scripts.
*   …and on and on

All code that was running on any of these servers was either saved as a script file in a temp directory on that server or as a script folder on a shared drive. It was a nightmare!

Believe it or not, for the most part, this system worked fine. Scripts ran as desired and we had backups on all servers anyway. No code was ever lost.

It was understandably easy for everyone to be happy with this status quo. Improving on this system wasn’t high on the priority list.

But this system wasn’t without its flaws. While it met the needs of some engineers, it wasn’t able to scale or be easily maintainable forever. This system also didn’t allow for any flexibility in the scheduled tasks either. This rigidness led to ten versions of the same script (with slight edits) being scheduled.

Enter Jenkins.

## Why Jenkins?

Of all the options you have to schedule and run PowerShell scripts, why choose Jenkins? Using a [Jenkins](https://adamtheautomator.com/tag/jenkins/) server to run PowerShell scripts provides many benefits. Here are a few highlights:

### Better Control

Once you have all of your PowerShell scripts in one place, there’s no wondering which server a script is run on. You are now able to forget about that script you wrote two years ago that is now outdated and locking out some service account.

You can organize scripts into an easily navigable folder structure, control exactly where all of your scripts actually execute and even use pipelines to break up large monolithic scripts into smaller modular chunks that can be reused in multiple jobs.

### Easy Scheduling

With Jenkins, you have a single, central place with full support for scheduling PowerShell script execution. You can schedule different scripts to run at different times with different parameters, have a  nice web GUI for managing schedules and more.

### Version Control

Having PowerShell scripts under some kind of version control solves many different problems. One of those is being able to integrate with tools like Jenkins. Jenkins can integrate with Git and other version control products to automatically pull the latest version.

### Consolidated Logging

When PowerShell scripts are spread out all over the place and creating logs, logs can be scattered everywhere. With Jenkins, you get excellent logging in a readable output window on a website instead of having to dig through some log file your scheduled task made.

## Prerequisites/Requirements

This article will be a walkthrough on how to set up Jenkins to run PowerShell scripts. As such, you’re going to need a few things to follow along.

*   [A running Jenkins server](https://jenkins.io/download/)
*   Git installed on your Jenkins server or [build agent](https://wiki.jenkins.io/display/JENKINS/Distributed+builds)
*   A Git repo set up containing your PowerShell scripts (Be sure you know the repo URL)
*   [Jenkins Git plugin](https://wiki.jenkins.io/display/JENKINS/Git+Plugin)

## Installing the PowerShell Plugin

To run PowerShell scripts with Jenkins, you’ll have to install the PowerShell plugin. To do so, at the main page:

1.  Click on _Manage Jenkins_ and then on _Manage Plugins_.
2.  Click on the _Available_ tab.
3.  On the right-hand side of the screen, type _powershell_ in the _Filter_ box. You should then see the PowerShell plugin appear as shown below.

![Looking for the PowerShell extension](https://adamtheautomator.com/wp-content/uploads/2020/06/PowerShell-plugin-appear-as-shown-below.-1024x189.png)

Looking for the PowerShell extension

4\.  Select the _Install_ checkbox and click _Install without restart_.

5\.  Installing the PowerShell plugin will create a _Windows PowerShell_ build step option when you provide the PowerShell script to run a little later.

## Creating a Job

Jenkins has a concept of _[jobs](https://www.tutorialspoint.com/jenkins/jenkins_setup_build_jobs.htm)_. A job is a set of instructions that you can provide Jenkins to know what scripts to execute, schedules to adhere to, etc. You’ll create a job in this section that will execute a PowerShell script. To do so, you’ll set up a job that will clone a Git repository into Jenkins.

1.  Once logged in Jenkins, click _New Item_ in the upper right-hand corner.

![New Item menu option](https://adamtheautomator.com/wp-content/uploads/2020/06/New-Item-in-the-upper-right-hand-corner..png)

New Item menu option

2\.  You’ll then be provided with the screen shown below. Select _Freestyle project._ This type of job will allow the most flexibility.

![Creating a new Jenkins project](https://adamtheautomator.com/wp-content/uploads/2020/06/most-flexibility..png)

Creating a new Jenkins project

3\.  Give the job the name _Hello World_ and click _OK._

![Using Hello World for the project name](https://adamtheautomator.com/wp-content/uploads/2020/06/Hello-World-and-click-OK..png)

Using Hello World for the project name

4\.  You should now be at the _Job Configuration_ screen. You should now see a section called _Source Code Management_ as shown below. This allows you to specify which Git repo Jenkins will clone to make available to the job. For this demo, choose _Git_.

![Source Code Management option](https://adamtheautomator.com/wp-content/uploads/2020/06/this-demo-choose-Git..png)

Source Code Management option

5\.  When you click on _Git_, you should now see an option asking you for your Git repository information. This is the Git repo that contains your PowerShell scripts.

![Setting the Git repo](https://adamtheautomator.com/wp-content/uploads/2020/06/This-is-the-Git-repo-that-contains-your-PowerShell-scripts..png)

Setting the Git repo

Below is a breakdown of each field:

*   _Repository URL_ – The URL pointing to the Git repo. In TFS, for example, the URL may look like this: \*http://SERVERNAME:8080/tfs//Messaging/\_git/Dynamic Distro List\*
*   _Credentials_ – A username/password that that has access to the repository. If you don’t have a credential already set up, you can create one by clicking on _Add._
*   _Name_ – This can be left blank.
*   _Refspec_ -This can be left blank.
*   _Branch Specifier_ – This allows you to choose what branch you want this job to use. By default, it is going to pull the _master_ branch, but if you have another testing branch you want to use, you can specify it here.

> _You can also clone more than one repository for a job by using the Add Repository button above. This is useful if you have modules or other dependencies that you need in a separate repository._

## Adding the Windows PowerShell Build Step

Perhaps you have a script in the root of the Git repo’s master branch called _Hello World.ps1_. Inside of this script, you have a single line:

```powershell
Write-Host "Hello World, I'm a Jenkins build!"
```

You’d like to execute this script when the job runs. To do so, you’ll have to create a build step.

Jenkins allows you to specify numerous build steps per job. For your purposes, you need to add a _Windows PowerShell_ build step. To do so, at the job configuration screen:

1.  Click on the _Add build step_ button and choose _Windows PowerShell_.

![Windows PowerShell Build step](https://adamtheautomator.com/wp-content/uploads/2020/06/choose-Windows-PowerShell..png)

Windows PowerShell Build step

2\.  Inside of the _Command_ box, [dot source](https://mcpmag.com/articles/2017/02/02/exploring-dot-sourcing-in-powershell.aspx) the PowerShell script located in your Git repo as shown below. You can see we’re using a PowerShell [environment variable](https://adamtheautomator.com/powershell-environment-variables/ "environment variable") called `WORKSPACE`. This variable represents the current working directory (the root folder of the Git repo).

![Running the Hello World.ps1 script](https://adamtheautomator.com/wp-content/uploads/2020/06/This-variable-represents-the-current-working-directory-the-root-folder-of-the-Git-repo..png)

Running the Hello World.ps1 script

3\.  Now click on _Save_ to save the job.

You should now have a job set up to invoke a PowerShell script from a Git repo!

## Executing the PowerShell Script

Now that you have created a job, run it and take a look at the output.

1.  Ensure you’re at the main job screen. If you used the _Hello World_ name for this job, the default URL will be _[http://localhost:8080/job/Hello](http://localhost:8080/job/Hello) world/_.
2.  On the main job screen, click _Build Now_ on the left-hand side as shown below.

![Running the build](https://adamtheautomator.com/wp-content/uploads/2020/06/On-the-main-job-screen-click-Build-Now-on-the-left-hand-side-as-shown-below.png)

Running the build

Clicking on _Build Now_ immediately launches a build of the current job. For jobs that are complex and take a while to run, you will have the ability to click the build and see the output in real-time as it runs. In this case, however, the job will run practically instantly.

4\.  To see the results, click the green check next to the build.

![Inspecting build results](https://adamtheautomator.com/wp-content/uploads/2020/06/see-the-results-click-the-green-check-next-to-the-build.-1.png)

Inspecting build results

If all went according to plan, you will see something like the following in your output:

![Build log results](https://adamtheautomator.com/wp-content/uploads/2020/06/your-output-1024x402.png)

Build log results

## Schedules and Triggers

You now have a job that can run whenever needed and that outputs the _Hello World_ message. But one of the major selling points of Jenkins is to replace scheduled tasks. We don’t want to have to go in and manually run it. If you reopen that job, you will see a section called _Build Triggers_.

![Available build triggers](https://adamtheautomator.com/wp-content/uploads/2020/06/called-Build-Triggers..png)

Available build triggers

These are your options for having a job run without requiring that you click on _Build Now_ in Jenkins.

### Creating a Schedule

There are a few different options to create triggers from. In this example, let’s keep it simple.

1.  Select _Build periodically_. This trigger allows you to schedule jobs using a [cron-like scheduling syntax](https://www.ostechnix.com/a-beginners-guide-to-cron-jobs/).

2\. Set the job to run at at 7: 30 a.m. Monday, Wednesday, and Friday as shown below.

![Setting schedule to 7:30AM MWF](https://adamtheautomator.com/wp-content/uploads/2020/06/shown-below.-1024x128.png)

Setting schedule to 7:30AM MWF

3\.  Save the changes and wait.

When the assigned date and time occurs, you will then see the script ran as desired under _Build History_.

![Build running on schedule](https://adamtheautomator.com/wp-content/uploads/2020/06/under-Build-History..png)

Build running on schedule

You now have a PowerShell script scheduled in Jenkins that will execute at a recurring interval.

## Further Reading

*   **_[Automating with Jenkins and PowerShell on Windows](https://hodgkins.io/automating-with-jenkins-and-powershell-on-windows-part-1)_**

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-jenkins%2F&text=Integrate%20Git%20%26%20Jenkins%20for%20Scheduled%20PowerShell%20Scripts)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-jenkins%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-jenkins%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/featured_image-20.png)

### [Deploy Enterprise PowerShell Modules Using Azure Artifacts](/deploy-enterprise-powershell-modules-using-azure/)

Build a private PowerShell repository using Azure Artifacts with automated CI/CD publishing, semantic versioning, code signing, and JEA integration for secure enterprise module distribution.

![](https://adamtheautomator.com/wp-content/uploads/2025/01/featured-image-5.webp)

### [Build a Scalable PowerShell Pester Testing Framework](/powershell-pester-testing-framework/)

Learn how to create a maintainable and organized Pester testing framework for PowerShell that scales with your needs. Perfect for large test suites.

![](https://adamtheautomator.com/wp-content/uploads/2022/05/Focused-Job-Configuration-with-the-Jenkins-DSL-Plugin.jpg)

### [Focused Job Configuration with the Jenkins DSL Plugin](/jenkins-dsl/)

Learn the fundamentals of using the Jenkins DSL plugin to craft infrastructure as code and generate focused Jenkins jobs!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
