PoshCode Archive  Artifact [b7e7b184b3]

Artifact b7e7b184b31d9bbfa11f00a5717fdbb2fecd187df6af92be6b81cbcc7a3781c9:

  • File gpupdate-on-remote-pc-s.ps1 — part of check-in [e8fa231359] at 2018-06-10 13:18:13 on branch trunk — This script gets all pc’s or servers from a OU and runs GPUpdate /force on these machines. (user: afokkema size: 2270)

# encoding: ascii
# api: powershell
# title: gpupdate on remote pc's
# description: This script gets all pc’s or servers from a OU and runs GPUpdate /force on these machines.
# version: 1.0
# author: afokkema
# license: CC0
# x-poshcode-id: 2985
# x-archived: 2012-01-14T07:05:49
# x-published: 2012-10-05T09:20:00
#
# - you need the Quest AD cmdlets.
# Source: www.ict-freak.nl
#
###############################################################################
# 
# Get all servers from a OU and run GPUpdate /force on this machines.
# 
# Version 1.0
#
# (C) 2009 - Arne Fokkema
# www.ict-freak.nl 
#
# Install the Quest AD cmdlets first!!
# 
###############################################################################

# Requires QAD cmdlets
if ((Get-PSSnapin "Quest.ActiveRoles.ADManagement" `
            -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Quest.ActiveRoles.ADManagement"
}

$url = "http://live.sysinternals.com/psexec.exe"
$target = "c:\Tools\psexec.exe"
$TempFile = "C:\Machines.txt"
$Domain = Read-Host ("Enter the FQDN of the Domain")
$OU = Read-Host ("Enter the name of the OU")

# Check if psexec does exist
if (test-path $target)
{
write-host "psexec.exe is already installed"
} 
else
{
write-host "psexec.exe doesn't exist"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $target);
write-host "psexec.exe is now installed"
}


$Servers = Get-QADComputer -SearchRoot $Domain/$OU | Select Name | out-file $TempFile -force

#Cleanup Textfile
(Get-Content $TempFile) | Foreach-Object {$_ -replace "Name                                                                           ", ""} | Set-Content $TempFile
(Get-Content $TempFile) | Foreach-Object {$_ -replace "----                                                                           ", ""} | Set-Content $TempFile
(Get-Content $TempFile) | Foreach-Object {$_ -replace "                                                                       ", ""} | Set-Content $TempFile
(Get-Content $TempFile) | where {$_ -ne ""} >$TempFile

$colComputers = Get-Content $TempFile
Foreach ($strComputer in $colComputers){c:\Tools\psexec.exe \\$strComputer gpupdate.exe /target:computer /force}
	
RM $TempFile