Mit den Office 365 Deployment-Tool kann man zentralisiert Updates fürs Netz bereitstellen: Technet-Artikel 

Per Task-Scheduler lässt man dann folgendes Script laufen. Damit werden dann aktuelle Updates heruntergeladen und alte Updates gelöscht…

Vorher muss natürlich per XML-File das Tool korrekt konfiguriert werden. Im verlinkten Artikel sind alle Infos dafür zu finden.

 

param
	(
	[string]$Path="F:\Office-Update\Office\Data",
	[int]$Keep=5,
	[int]$MaxOld=45,
	[switch]$Whatif,
	[switch]$Debug
	)
$Error.Clear()

#--------------------------------------------------------------------------------------------------
# Write LOG
#--------------------------------------------------------------------------------------------------
function write-log
	{
	param
		(
		[string]$String,
		[switch]$SizeCheck,
		[switch]$Err,
		[switch]$NoPrefix
 		)
	$LogHistory=5
	$ErrCount = $Error.count
	$LogFile = Join-Path -Path $PSScriptRoot -ChildPath "LogFile.log"
	if ( $SizeCheck )
		{
		$LF = Get-Item -Path $LogFile -ErrorAction silentlycontinue
		if ( $LF.Length -gt 100KB)
			{
			if ( $LogHistory )
				{
				for($i=$LogHistory - 1; $i -ge 1; $i--)
					{
					if ( test-path $($LF.FullName + "." + $i.tostring() ) )
						{
						Move-Item -Path $($LF.FullName + "." + $i.tostring() ) -Destination $($LF.FullName + "." + $($i + 1).tostring() ) -force
						}
					}
				}
			Move-Item -Path $LF.FullName -Destination $($LF.FullName + ".1" ) -force
			write-log "Moved LogFile $LogFile to $($LF.FullName + ".1" ) because of size: $($LF.Length)"
			}
		}

	$Datum = get-date -Format G
	if ( -not $Err)
		{
		if ( -not $NoPrefix )
			{
			$Prefix = "`($($myInvocation.ScriptName.Split('\')[-1])`[$($MyInvocation.ScriptLineNumber)`]`)"
			$TMP  = "$($Datum) $($Prefix): $String"
			}
		else
			{
			$TMP = $String
			}
		}
	else
		{
		if ( $String ) { write-log $String }
		
		foreach ( $E in $Error )
			{
			$Prefix = "`($($myInvocation.ScriptName.Split('\')[-1])`[$($E.InvocationInfo.ScriptLineNumber) '/ $($E.InvocationInfo.OffsetInLine)`]`)"
			$TMP = "$($Datum) $($Prefix): $($E.Exception.Message)"
			write-log -String $TMP -NoPrefix
			}
		}
		
	if ( $Debug )
		{ $TMP }
	$TMP | Out-File -append -encoding UTF8 -FilePath $LogFile -ErrorAction silentlycontinue
	if ($ErrCount -eq 0)
		{ $Error.Clear() }
	}
#--------------------------------------------------------------------------------------------------
# Ende -- Cleanup end exit
#--------------------------------------------------------------------------------------------------
function ende
	{
	param
	(
		[String]$Text
		)
	if ( $Text )
		{
		write-log $Text
		}
	else
		{
		write-log "Exit Script."
		}
	$Session = Get-PSSession
	if ( $Session )
		{
		$Session | Remove-PSSession
		}
	exit
	}
#--------------------------------------------------------------------------------------------------

if ( $Error )
	{
	write-log "Include of Functions or Definitions failed" -Err
	write-error "Include of Functions or Definitions failed"
	ende
	exit 		# Maybe "ende" ist not defined
	}
write-log "Start Script Manage-O365Updates." -SizeCheck

if ( -not ( Test-Path $Path -PathType Container ))
	{
	write-log "$Path ist kein gültiger Pfad. Exit."
	ende
	}

write-log "Set Location to $PSScriptRoot"
Set-Location $PSScriptRoot

if ( -not (test-path .\setup.exe) )
	{
	write-log "setup.exe not found. Exit."
	ende
	}
write-log "Check for new Updates..."
.\setup.exe /download
write-log "Check for Update done."	

if ( $Error )
	{
	write-log "Problems downloading Updates. Exit" -Err
	ende
	}

write-log "Cleanup old Opbject (older then $MaxOld Days)"	
$FileItems = Get-ChildItem $Path -File | Sort-Object CreationTime
$DirItems = Get-ChildItem $Path -Directory | Sort-Object CreationTime

If ( $DirItems.Count -lt $Keep )
	{
	Write-log "Anzahl der gefunden Objekte $($DirItems.Count) ist kleiner oder gleich $Keep. Exit"
	ende
	}

$Items = $DirItems[$($keep)..$($DirItems.Count)] + $FileItems[$($keep)..$($FileItems.Count)] | where { ($(get-date) - $_.CreationTime).Days -gt $MaxOld }

if ( $Error )
	{
	write-log "Problems counting Files. Exit" -Err
	ende
	}

foreach( $Item in $Items )
	{
	write-log "Delete $($Item.FullName)"
	Remove-Item -Path $Item.FullName -Recurse -Force -WhatIf:$Whatif
	}
ende

 

Update für Click-to-Run

Das könnte dir auch gefallen

Schreibe einen Kommentar