SID-500

Home » PowerShell » How to schedule software installation with PowerShell

How to schedule software installation with PowerShell

Under certain circumstances the installation of software can only take place at a specific time. This article describes the establishing of a scheduled installation on the localhost and on remote hosts.

Scheduling an installation job for the localhost

I am logged on server dc01. Dc01 must install the windowsfeature Windows-Server-Backup at 10:30 am. First, i have to provide a trigger. Then i need a Scheduled Job. So, i run in PowerShell ISE

$trigger=New-JobTrigger -Once -At "7/28/2017 10:30 AM"
Register-ScheduledJob -Name WSBackupInstall -ScriptBlock {Install-WindowsFeature -Name Windows-Server-Backup} -Trigger $trigger

1.PNG

To make sure the job was running and completed successfully use Get-Job.

Get-Job | Select-Object *

1.PNG

Scheduling an installation job for a remote host

To do the same on a remote host simply add the command Invoke-Command and the parameter computername. Make sure, that both hosts are in the same domain. If they don´t share the same domain you have to configure them as Trusted Hosts. More about Trusted Hosts in  my article: How to configure Trusted Hosts for PowerShell Remote Sessions.

I am logged on server dc01. I want to schedule a job on server02.

Invoke-Command -ComputerName server02 -ScriptBlock {Register-ScheduledJob -Name WSBackupInstall -ScriptBlock {Install-WindowsFeature -ComputerName server02 -Name Windows-Server-Backup} -Trigger (New-JobTrigger -Once -At "7/28/2017 10:30 AM")}

To make sure, that the software was installed on the remote computer run

Invoke-Command -ComputerName server02 {Get-Job | Select-Object PSComputerName,PSBeginTime,PSEndtime; Get-WindowsFeature Windows-Server-Backup | Select-Object Name,PSComputerName,Installstate}

1.PNG

See also

For scheduling the automatic start of PowerShell at logon see my article Configuring the automatic start of Powershell at every logon.


1 Comment

  1. […] For further information about Scheduled Jobs see also: How to schedule software installation with PowerShell […]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

Who is the blogger?

My name is Patrick Grünauer (pewa2303). I am from Austria. On sid-500 I write about Windows, Cisco and IT-Security in English and German. Have fun while reading!

Patrick Gruenauer
Follow SID-500 on WordPress.com