我正在寻找一个脚本的帮助:
将在子文件夹中搜索,并且每次找到WIM文件时,都会使用wsus的最新更新进行更新。当该脚本完成后,它将继续下一个子文件夹。
这里有你到目前为止的代码:
$thismonth = (get-date).AddMonths(0).ToString("yyyMM")
$lastmonth = (get-date).AddMonths(-1).ToString("yyyMM")
$2ndlastmonth = (get-date).AddMonths(-2).ToString("yyyMM")
$date = get-date -f "yyyMM"
$LogName = "wim_update_$($thismonth).log"
$UpdatesPath = "d:\WSUS\WsusContent\*"
$MountPath = “d:\temp\mount”
$folder = Get-ChildItem -Path "D:\Distribution\Operating Systems"
########### DISM Mount path ########
Set-Location "d:\Distribution\Servicing\x86\"
forEach ($os in $folder)
{
###########Alias########
$WimFile = “d:\Distribution\Operating Systems\$os\sources\install.wim"
Write-Host $WimFile
if (-Not (Test-Path ($Wimfile))) { continue }
########### Backup WIM File########
Copy-Item "d:\Distribution\Operating Systems\$os\sources\install.wim" -Destination "d:\backup\install-$os-$thismonth.wim"
if (-Not $?)
{
Write-Host "Failed to copy WIM file"
continue
}
./DISM /Mount-Wim /WimFile:$WimFile /index:1 /Mountdir:$MountPath
if (-Not $?)
{
Write-Host "Failed to mount WIM file"
continue
}
############ Apply updates
$UpdateArray = Get-Item $UpdatesPath | where{$_.extension -eq ".cab"}
ForEach ($Updates in $UpdateArray)
{
./DISM /image:$MountPath /LogPath:d:\Temp\$LogName /LogLevel:3 /Format:List /Add-Package /Packagepath:$Updates
Start-Sleep –s 10
}
Write-Host "Updates Applied to WIM" -foregroundcolor red -backgroundcolor yellow
./DISM /Commit-Wim /Mountdir:$MountPath
########### DISM : Unmount WIM file ########
./DISM /Unmount-Wim /Mountdir:$MountPath /commit
./DISM /Cleanup-Wim
}
###########Remove N-2 ########
#Remove-Item "d:\backup\$os\install-$os-$2ndlastmonth.wim"