You are browsing the archive for applications.

MMS 2015 unplugged: Unable to publish application globally if targeted user-based within Configmgr workaround

2:55 pm in App-V, App-V 5.0, Application Model, applications, AppV, ConfigMgr 2012, configmgr 2012 R2, ConfigMgr 2012 R2 SP1, ConfigMgr 2012 SP1, ConfigMgr SP2, ConfigMgr V.next, sccm, sccm 2012 R2, SCCM 2012 R2, SCCM 2012 R2 SP1, SCCM 2012 SP1, SCCM v.Next by Kenny Buntinx [MVP]

 

If you have been to our session called App-V standalone compared to CM12 Integrated: The Good, The Bad and The Ugly at MMS 2015 , we have showed you that some things by default cannot be done in Configmgr .

We showed a strong business case around the Application model in CM12 SP1 and using App-V 5.0 to do user-based software targeting. As most people are doing App-V integration in Configuration Manager and exploring the possibilities , they ran into some challenges I believe are critical and needs to be solved in a certain way . What the correct way is , I leave that up to the smart engineering guy’s in Redmond .

One of the great promises of application virtualization is dynamic delivery of software to end-users; however delivering plug-ins or add-ons to installed (i.e. not virtualized) software has thus far been a stumbling block. Internet Explorer has been particularly challenging due to the inability to separate the browser from the OS in a supported manner. So using App-V to deploy plug-ins like Flash or Java has meant changing the user experience with virtualization or falling back to standard install methods. Since App-V 5.0 SP2 this is very good news though, with the ability to seamlessly run an installed application inside a specified virtual environment. This means that the Flash plug-in can be delivered as a virtual package and made available to Internet Explorer without resorting to hacks or changing the user experience by providing a special shortcut.

The only requirement for specific Virtual Extensions (like the flash add-in) is that the package needs to be published Globally… only it doesn’t work great when deploying all your virtualized apps to users with System Center Configuration Manager and App-V 5.x. The table below will explain in what cases you will have to use Global publishing.

imageimage

We can overcome that hurdle with a sort of workaround that we are not going to explain in absolute detail as every customer has specific needs. See the steps below as a guide to think outside the box.

Workaround :

1. We are going to create a scheduled task which triggers on a eventID action 1003 from the eventlog “Microsoft-AppV-Client/Operational”

The script to create the scheduled task :

param( [Parameter(ParameterSetName='Register')] [switch]$Register, [Parameter(ParameterSetName='UnRegister')] [switch]$UnRegister ) switch($PsCmdlet.ParameterSetName){ "Register"{ $Xml = Get-Content (Join-Path $PSScriptRoot "ScheduledTaskTemplate_Publish.xml") $hReplace = @{ _Date_=(Get-Date -Format s) _Author_="Publish_User2Global_1.0_EN" _WorkingDirectory_=$PSScriptRoot } foreach($key in $hReplace.Keys) { $Xml = $Xml -creplace $key, $hReplace.$key } Register-ScheduledTask -Xml ($Xml | Out-String) -TaskName "1_user_Publish_User2Global" -TaskPath "Microsoft\AppV\Publishing" -Force | Out-Null $Xml = Get-Content (Join-Path $PSScriptRoot "ScheduledTaskTemplate_UnPublish.xml") $hReplace = @{ _Date_=(Get-Date -Format s) _Author_="UnPublish_User2Global_1.0_EN" _WorkingDirectory_=$PSScriptRoot } foreach($key in $hReplace.Keys) { $Xml = $Xml -creplace $key, $hReplace.$key } #Register-ScheduledTask -Xml ($Xml | Out-String) -TaskName "1_user_UnPublish_User2Global" -TaskPath "Microsoft\AppV\Publishing" -Force | Out-Null } "UnRegister"{ Get-ScheduledTask -TaskPath "\Microsoft\AppV\Publishing\" -TaskName "1_user_Publish_User2Global" | Unregister-ScheduledTask -Confirm:$False | Out-Null #Get-ScheduledTask -TaskPath "\Microsoft\AppV\Publishing\" -TaskName "1_user_UnPublish_User2Global" | Unregister-ScheduledTask -Confirm:$False | Out-Null } }

The script is based on the following templates :

<?xml version="1.0" encoding="UTF-16"?> <Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>_Date_</Date> <Author>_Author_</Author> <URI>\Microsoft\AppV\Publishing\1_user_Publish_User2Global</URI> </RegistrationInfo> <Triggers> <EventTrigger> <Enabled>true</Enabled> <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-AppV-Client/Operational"&gt;&lt;Select Path="Microsoft-AppV-Client/Operational"&gt;*[System[Provider[@Name='Microsoft-AppV-Client'] and EventID=1003]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription> <ValueQueries> <Value name="ThePackageId">Event/EventData/Data[@Name='Package']</Value> <Value name="TheVersionId">Event/EventData/Data[@Name='Version']</Value> <Value name="UserSid">Event/System/Security/@UserID</Value> </ValueQueries> </EventTrigger> </Triggers> <Principals> <Principal id="Author"> <GroupId>S-1-5-18</GroupId> <RunLevel>LeastPrivilege</RunLevel> </Principal> </Principals> <Settings> <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries> <AllowHardTerminate>true</AllowHardTerminate> <StartWhenAvailable>false</StartWhenAvailable> <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> <IdleSettings> <StopOnIdleEnd>true</StopOnIdleEnd> <RestartOnIdle>false</RestartOnIdle> </IdleSettings> <AllowStartOnDemand>false</AllowStartOnDemand> <Enabled>true</Enabled> <Hidden>true</Hidden> <RunOnlyIfIdle>false</RunOnlyIfIdle> <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession> <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine> <WakeToRun>false</WakeToRun> <ExecutionTimeLimit>P3D</ExecutionTimeLimit> <Priority>7</Priority> <RestartOnFailure> <Interval>PT1M</Interval> <Count>3</Count> </RestartOnFailure> </Settings> <Actions Context="Author"> <Exec> <Command>powershell.exe</Command> <Arguments>-NonInteractive -ExecutionPolicy RemoteSigned -WindowStyle Hidden -File User2Global.ps1 -Publish -PackageId $(ThePackageId) -VersionId $(TheVersionId) -UserSid $(UserSid)</Arguments> <WorkingDirectory>_WorkingDirectory_</WorkingDirectory> </Exec> </Actions> </Task>

2. When the scheduled task is triggered by event-ID action 1003 from the eventlog “Microsoft-AppV-Client/Operational” , we kick-off the following Powershell script (see below). It will unpublished the  package from the user and will publish the package globally instead.

param( [Parameter(ParameterSetName='Publish')] [switch]$Publish, [Parameter(ParameterSetName='UnPublish')] [switch]$UnPublish, [guid]$PackageId, [guid]$VersionId, [string]$UserSid ) Function New-BurntToastNotification{ <# This function will show a BurnToastNotification #> [CmdletBinding(SupportsShouldProcess = $True)] Param ( [Parameter(Mandatory=$True)] $Text, [Parameter(Mandatory=$True)] $Title ) # create toast template TO xml [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null $toastXml = ([Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastImageAndText02)).GetXml() # message to show on toast $stringElements = $toastXml.GetElementsByTagName("text") | select -First 1 $stringElements.AppendChild($toastXml.CreateTextNode($Title)) > $null $stringElements = $toastXml.GetElementsByTagName("text") | select -Last 1 $stringElements.AppendChild($toastXml.CreateTextNode($Text)) > $null # image $imageElements = $toastXml.GetElementsByTagName("image") $imageElements[0].src = "file:///" + "$PSScriptRoot\appv.png" # convert from System.Xml.XmlDocument to Windows.Data.Xml.Dom.XmlDocument $windowsXml = New-Object Windows.Data.Xml.Dom.XmlDocument $windowsXml.LoadXml($toastXml.OuterXml) # send toast notification $toast = New-Object Windows.UI.Notifications.ToastNotification ($windowsXml) [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("App-V").Show($toast) } Import-Module "$env:ProgramFiles\Microsoft Application Virtualization\Client\AppvClient\AppvClient.psd1" $package = Get-AppVClientPackage -PackageId $PackageId -VersionId $VersionId -All switch($PsCmdlet.ParameterSetName) { "Publish" { try { Unpublish-AppvClientPackage $package -UserSID $UserSid if (! $package.IsPublishedGlobally) { Publish-AppVClientPackage $package -Global New-BurntToastNotification -Text "$($package.name)`nSuccesfully Published Globally." -Title "App-V User2Global" } } catch { New-BurntToastNotification -Text "Something went wrong while Publishing: `n$($package.name)." -Title "App-V User2Global" } } "UnPublish" { try { if (($package = Get-AppVClientPackage -PackageId $PackageId -VersionId $VersionId -All).IsPublishedGlobally) { $package | stop-AppVClientPackage -Global -ErrorAction SilentlyContinue | Unpublish-AppvClientPackage -Global New-BurntToastNotification -Text "$($package.name)`nSuccesfully UnPublished Globally." -Title "App-V User2Global" } } catch { New-BurntToastNotification -Text "Something went wrong while unpublishing: `n$($package.name)." -Title "App-V User2Global" } } }

You can choose how to deploy the script. You can create an App-V bubble or simply deploy this with Configmgr or GPO ….

Disclaimer : The script are delivered AS-IS and are not the complete solution to this story. It is an example on how to think outside the box and make a potential solution that will fit your specific company issue.

Hope it Helps ,

Kenny Buntinx & Roy Essers .

MMS 2015 unplugged : Preparing your App-V sequencer the right “automated” way

1:18 pm in App-V, App-V 5.0, applications, AppV, powershell, sequencing by Kenny Buntinx [MVP]

 

First of all – sorry for the delay as we promised to post this script much earlier. However as usual there are only 48 hours in a day :-)

If you attended our session “Sequencing applications with App-V 5.1 – Best Practices Edition”, Roy Essers and me showed you the latest techniques to prepare and analyze to virtualize apps using the latest version of Microsoft App-V. One of those best practices techniques is to prepare your sequencer the automated way  :

Another App-V MVP called Dan Gough originally created this script , but it wasn’t really a good solution in our eyes. The reason for that , was that it uses modules from chocolatey and boxstarter directly of the internet and we didn’t trust the big bad cloudy internet. Anyone could change the source code and inject malicious code anytime . Also changes made in revisions would also create an inconsistency in your build platform.

You will find the script below and we provide it AS-IS with no support :

# Disclaimer: This script is provided as-is, without warranty of any kind # # App-V sequencer / client generic build script # Version 1.0 - Dan Gough 04/07/15 # Version 1.1 - Fixed HideSCAHealth registry key # Version 1.2 - Fixed install on 32-bit Windows # Version 1.3 - Update for .NET 4.6 and Windows 10, better method of disabling Defender on Win8+ # Version 1.4 - Roy Essers - added native functions from chocolatey and boxstarter (so no need for those modules). # -sequencer only # -depends on local sources (dotnet, wmf, etc), if not found will try to download them from the internet # -added some features, onedrive removal. # planning to add option to (download and) install vcredists function Download-File() { <# .SYNOPSIS Downloads a file showing the progress of the download .DESCRIPTION This Script will download a file locally while showing the progress of the download .EXAMPLE .\Download-File.ps1 'http:\\someurl.com\somefile.zip' .EXAMPLE .\Download-File.ps1 'http:\\someurl.com\somefile.zip' 'C:\Temp\somefile.zip' .PARAMETER url url to be downloaded .PARAMETER localFile the local filename where the download should be placed .NOTES FileName : Download-File.ps1 Author : CrazyDave LastModified : 18 Jan 2011 9:39 AM PST #Requires -Version 2.0 #> param( [Parameter(Mandatory=$true)] [String] $url, [Parameter(Mandatory=$false)] [String] $localFile = (Join-Path $pwd.Path $url.SubString($url.LastIndexOf('/'))) ) begin { $client = New-Object System.Net.WebClient $Global:downloadComplete = $false $eventDataComplete = Register-ObjectEvent $client DownloadFileCompleted ` -SourceIdentifier WebClient.DownloadFileComplete ` -Action {$Global:downloadComplete = $true} $eventDataProgress = Register-ObjectEvent $client DownloadProgressChanged ` -SourceIdentifier WebClient.DownloadProgressChanged ` -Action { $Global:DPCEventArgs = $EventArgs } } process { Write-Progress -Activity 'Downloading file' -Status $url $client.DownloadFileAsync($url, $localFile) while (!($Global:downloadComplete)) { $pc = $Global:DPCEventArgs.ProgressPercentage if ($pc -ne $null) { Write-Progress -Activity 'Downloading file' -Status $url -PercentComplete $pc } } Write-Progress -Activity 'Downloading file' -Status $url -Complete } end { Unregister-Event -SourceIdentifier WebClient.DownloadProgressChanged Unregister-Event -SourceIdentifier WebClient.DownloadFileComplete $client.Dispose() $Global:downloadComplete = $null $Global:DPCEventArgs = $null Remove-Variable client Remove-Variable eventDataComplete Remove-Variable eventDataProgress [GC]::Collect() } } function Install-PinnedTaskBarItem { <# .SYNOPSIS Creates an item in the task bar linking to the provided path. .PARAMETER TargetFilePath The path to the application that should be launched when clicking on the task bar icon. .EXAMPLE Install-PinnedTaskBarItem "${env:ProgramFiles(x86)}\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" This will create a Visual Studio task bar icon. #> param( [string] $targetFilePath ) Write-Debug "Running 'Install-PinnedTaskBarItem' with targetFilePath:`'$targetFilePath`'"; if (Test-Path($targetFilePath)) { $verb = "Pin To Taskbar" $path= split-path $targetFilePath $shell=new-object -com "Shell.Application" $folder=$shell.Namespace($path) $item = $folder.Parsename((split-path $targetFilePath -leaf)) $itemVerb = $item.Verbs() | ? {$_.Name.Replace("&","") -eq $verb} if($itemVerb -eq $null){ Write-Host "TaskBar verb not found for $item. It may have already been pinned" -ForegroundColor Yellow } else { $itemVerb.DoIt() } Write-host "`'$((Get-ChildItem $targetFilePath).Name)`' has been pinned to the task bar on your desktop." -ForegroundColor Green } else { $errorMessage = "`'$((Get-ChildItem $targetFilePath).Name)`' does not exist, not able to pin to task bar" } if($errorMessage){ Write-host $errorMessage -ForegroundColor Red throw $errorMessage } } function Set-StartScreenOptions { <# .SYNOPSIS Sets options for the Windows Start Screen. .PARAMETER EnableBootToDesktop When I sign in or close all apps on a screen, go to the desktop instead of Start .PARAMETER DisableBootToDesktop Disables the Boot to Desktop Option, see enableBootToDesktop .PARAMETER EnableDesktopBackgroundOnStart Show Desktop background on Start .PARAMETER DisableDesktopBackgroundOnStart Do not show Desktop background on Start .PARAMETER EnableShowStartOnActiveScreen Show Start on the display I'm using when I press the Windows logo key .PARAMETER DisableShowStartOnActiveScreen Disables the displaying of the Start screen on active screen, see enableShowStartOnActiveScreen .PARAMETER EnableShowAppsViewOnStartScreen Show the Apps view automatically when I go to Start PARAMETER DisableShowAppsViewOnStartScreen Disables the showing of Apps View when Start is activated, see enableShowAppsViewOnStartScreen .PARAMETER EnableSearchEverywhereInAppsView Search everywhere instead of just my apps when I search from the Apps View .PARAMETER DisableSearchEverywhereInAppsView Disables the searching of everywhere instead of just apps, see enableSearchEverywhereInAppsView .PARAMETER EnableListDesktopAppsFirst List desktop apps first in the Apps view when it's sorted by category .PARAMETER DisableListDesktopAppsFirst Disables the ability to list desktop apps first when sorted by category, see enableListDesktopAppsFirst .LINK http://boxstarter.org #> [CmdletBinding()] param( [switch]$EnableBootToDesktop, [switch]$DisableBootToDesktop, [switch]$EnableDesktopBackgroundOnStart, [switch]$DisableDesktopBackgroundOnStart, [switch]$EnableShowStartOnActiveScreen, [switch]$DisableShowStartOnActiveScreen, [switch]$EnableShowAppsViewOnStartScreen, [switch]$DisableShowAppsViewOnStartScreen, [switch]$EnableSearchEverywhereInAppsView, [switch]$DisableSearchEverywhereInAppsView, [switch]$EnableListDesktopAppsFirst, [switch]$DisableListDesktopAppsFirst ) $PSBoundParameters.Keys | %{ if($_-like "En*"){ $other="Dis" + $_.Substring(2)} if($_-like "Dis*"){ $other="En" + $_.Substring(3)} if($PSBoundParameters[$_] -and $PSBoundParameters[$other]){ throw new-Object -TypeName ArgumentException "You may not set both $_ and $other. You can only set one." } } $key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer' $startPageKey = "$key\StartPage" $accentKey = "$key\Accent" if(Test-Path -Path $startPageKey) { if($enableBootToDesktop) { Set-ItemProperty -Path $startPageKey -Name 'OpenAtLogon' -Value 0 } if($disableBootToDesktop) { Set-ItemProperty -Path $startPageKey -Name 'OpenAtLogon' -Value 1 } if($enableShowStartOnActiveScreen) { Set-ItemProperty -Path $startPageKey -Name 'MonitorOverride' -Value 1 } if($disableShowStartOnActiveScreen) { Set-ItemProperty -Path $startPageKey -Name 'MonitorOverride' -Value 0 } if($enableShowAppsViewOnStartScreen) { Set-ItemProperty -Path $startPageKey -Name 'MakeAllAppsDefault' -Value 1 } if($disableShowAppsViewOnStartScreen) { Set-ItemProperty -Path $startPageKey -Name 'MakeAllAppsDefault' -Value 0 } if($enableSearchEverywhereInAppsView) { Set-ItemProperty -Path $startPageKey -Name 'GlobalSearchInApps' -Value 1 } if($disableSearchEverywhereInAppsView) { Set-ItemProperty -Path $startPageKey -Name 'GlobalSearchInApps' -Value 0 } if($enableListDesktopAppsFirst) { Set-ItemProperty -Path $startPageKey -Name 'DesktopFirst' -Value 1 } if($disableListDesktopAppsFirst) { Set-ItemProperty -Path $startPageKey -Name 'DesktopFirst' -Value 0 } } if(Test-Path -Path $accentKey) { if($EnableDesktopBackgroundOnStart) { Set-ItemProperty -Path $accentKey -Name 'MotionAccentId_v1.00' -Value 219 } if($DisableDesktopBackgroundOnStart) { Set-ItemProperty -Path $accentKey -Name 'MotionAccentId_v1.00' -Value 221 } } } function Get-CurrentUser { <# .SYNOPSIS Returns the domain and username of the currently logged in user. #> $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent() $parts = $identity.Name -split "\\" return @{Domain=$parts[0];Name=$parts[1]} } function Restart-Explorer { try{ Write-Host "Restarting the Windows Explorer process..." -ForegroundColor Cyan $user = Get-CurrentUser try { $explorer = Get-Process -Name explorer -ErrorAction stop -IncludeUserName } catch {$global:error.RemoveAt(0)} if($explorer -ne $null) { $explorer | ? { $_.UserName -eq "$($user.Domain)\$($user.Name)"} | Stop-Process -Force -ErrorAction Stop | Out-Null } Start-Sleep 1 if(!(Get-Process -Name explorer -ErrorAction SilentlyContinue)) { $global:error.RemoveAt(0) start-Process -FilePath explorer } } catch {$global:error.RemoveAt(0)} } function Set-WindowsExplorerOptions { <# .SYNOPSIS Sets options on the Windows Explorer shell .PARAMETER EnableShowHiddenFilesFoldersDrives If this flag is set, hidden files will be shown in Windows Explorer .PARAMETER DisableShowHiddenFilesFoldersDrives Disables the showing on hidden files in Windows Explorer, see EnableShowHiddenFilesFoldersDrives .PARAMETER EnableShowProtectedOSFiles If this flag is set, hidden Operating System files will be shown in Windows Explorer .PARAMETER DisableShowProtectedOSFiles Disables the showing of hidden Operating System Files in Windows Explorer, see EnableShowProtectedOSFiles .PARAMETER EnableShowFileExtensions Setting this switch will cause Windows Explorer to include the file extension in file names .PARAMETER DisableShowFileExtensions Disables the showing of file extension in file names, see EnableShowFileExtensions .PARAMETER EnableShowFullPathInTitleBar Setting this switch will cause Windows Explorer to show the full folder path in the Title Bar .PARAMETER DisableShowFullPathInTitleBar Disables the showing of the full path in Windows Explorer Title Bar, see EnableShowFullPathInTitleBar .LINK http://boxstarter.org #> [CmdletBinding()] param( [switch]$EnableShowHiddenFilesFoldersDrives, [switch]$DisableShowHiddenFilesFoldersDrives, [switch]$EnableShowProtectedOSFiles, [switch]$DisableShowProtectedOSFiles, [switch]$EnableShowFileExtensions, [switch]$DisableShowFileExtensions, [switch]$EnableShowFullPathInTitleBar, [switch]$DisableShowFullPathInTitleBar ) $PSBoundParameters.Keys | % { if($_-like "En*"){ $other="Dis" + $_.Substring(2)} if($_-like "Dis*"){ $other="En" + $_.Substring(3)} if($PSBoundParameters[$_] -and $PSBoundParameters[$other]) { throw new-Object -TypeName ArgumentException "You may not set both $_ and $other. You can only set one." } } $key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer' $advancedKey = "$key\Advanced" $cabinetStateKey = "$key\CabinetState" Write-Host "Setting Windows Explorer options..." -ForegroundColor Cyan if(Test-Path -Path $advancedKey) { if($EnableShowHiddenFilesFoldersDrives) {Set-ItemProperty $advancedKey Hidden 1} if($DisableShowHiddenFilesFoldersDrives) {Set-ItemProperty $advancedKey Hidden 0} if($EnableShowFileExtensions) {Set-ItemProperty $advancedKey HideFileExt 0} if($DisableShowFileExtensions) {Set-ItemProperty $advancedKey HideFileExt 1} if($EnableShowProtectedOSFiles) {Set-ItemProperty $advancedKey ShowSuperHidden 1} if($DisableShowProtectedOSFiles) {Set-ItemProperty $advancedKey ShowSuperHidden 0} Restart-Explorer } if(Test-Path -Path $cabinetStateKey) { if($EnableShowFullPathInTitleBar) {Set-ItemProperty $cabinetStateKey FullPath 1} if($DisableShowFullPathInTitleBar) {Set-ItemProperty $cabinetStateKey FullPath 0} Restart-Explorer } } function Get-IsMicrosoftUpdateEnabled { <# .SYNOPSIS Returns $True if Microsoft Update is currently enabled .LINK http://boxstarter.org #> # Default response to false, unless proven otherwise $installed = $false $serviceManager = New-Object -ComObject Microsoft.Update.ServiceManager -Strict $serviceManager.ClientApplicationID = "Sequencer" foreach ($service in $serviceManager.Services) { if( $service.Name -eq "Microsoft Update") { $installed = $true; break; } } return $installed } function Enable-MicrosoftUpdate { <# .SYNOPSIS Turns on Microsoft Update, so additional updates for other Microsoft products, installed on the system, will be included when running Windows Update. .LINK http://boxstarter.org Disable-MicrsoftUpdate #> if(!(Get-IsMicrosoftUpdateEnabled)) { Write-Host "Microsoft Update is currently disabled." -ForegroundColor Yellow Write-Host "Enabling Microsoft Update..." -ForegroundColor Cyan $serviceManager = New-Object -ComObject Microsoft.Update.ServiceManager -Strict $serviceManager.ClientApplicationID = "Sequencer" $serviceManager.AddService2("7971f918-a847-4430-9279-4a52d1efe18d",7,"") } else { Write-Host "Microsoft Update is already enabled, no action will be taken." -ForegroundColor Green } } function Start-TimedSection { <# .SYNOPSIS Begins a timed section .DESCRIPTION A timed section is a portion of script that is timed. Used with Stop-TimedSection, the beginning and end of the section are logged to both the console and the log along with the amount of time elapsed. The function returns a guid that is used to identify the section when stopping it. .PARAMETER SectionName The Title or Label of the section being timed. This string is used in the logging to identify the section. .PARAMETER Verbose Instructs Start-TimedSection to write to the Verbose stream. Although this will always log messages to the Boxstarter log, it will only log to the console if the session's VerbosePreference is set to capture the Verbose stream or the -Verbose switch was set when calling Install-BoxstarterPackage. .EXAMPLE $session=Start-TimedSection "My First Section" Stop-TimedSection $session This creates a block as follows: + Boxstarter starting My First Section Some stuff happens here. + Boxstarter finished My First Section 00:00:00.2074282 .EXAMPLE Timed Sections can be nested or staggered. You can have multiple sections running at once. $session=Start-TimedSection "My First Section" $innerSession=Start-TimedSection "My Inner Section" Stop-TimedSection $innerSession Stop-TimedSection $session This creates a block as follows: + Boxstarter starting My First Section Some stuff happens here. ++ Boxstarter starting My Inner Section Some inner stuff happens here. ++ Boxstarter finished My Inner Section 00:00:00.1074282 Some more stuff happens here. + Boxstarter finished My First Section 00:00:00.2074282 Note that the number of '+' chars indicate nesting level. .EXAMPLE $session=Start-TimedSection "My First Section" -Verbose Stop-TimedSection $session This will write the start and finish messages to the Boxstarter log but will not write to the console unless the user has the the VerbosePreference variable or used the Verbose switch of Install-BoxstarterPackage. .NOTES If the SuppressLogging setting of the $Boxstarter variable is true, logging messages will be suppressed and not sent to the console or the log. .LINK http://boxstarter.org Stop-TimedSection about_boxstarter_logging #> param( [string]$sectionName, [switch]$Verbose) $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() $guid = [guid]::NewGuid().ToString() $timerEntry=@{title=$sectionName;stopwatch=$stopwatch;verbose=$Verbose} if(!$script:boxstarterTimers) {$script:boxstarterTimers=@{}} $boxstarterTimers.$guid=$timerEntry $padCars="".PadLeft($boxstarterTimers.Count,"+") Write-host "$sectionName" -ForegroundColor Cyan return $guid } function Stop-TimedSection { <# .SYNOPSIS Ends a timed section .DESCRIPTION A timed section is a portion of script that is timed. Used with Start-TimedSection, the beginning and end of the section are logged to both the console and the log along with the amount of time elapsed. .PARAMETER SectionId The guid that was generated by Start-TimedSection and identifies which section is ending. .EXAMPLE $session=Start-TimedSection "My First Section" Stop-TimedSection $session This creates a block as follows: + Boxstarter starting My First Section Some stuff happens here. + Boxstarter finished My First Section 00:00:00.2074282 .EXAMPLE Timed Sections can be nested or staggered. You can have multiple sections running at once. $session=Start-TimedSection "My First Section" $innerSession=Start-TimedSection "My Inner Section" Stop-TimedSection $innerSession Stop-TimedSection $session This creates a block as follows: + Boxstarter starting My First Section Some stuff happens here. ++ Boxstarter starting My Inner Section Some inner stuff happens here. ++ Boxstarter finished My Inner Section 00:00:00.1074282 Some more stuff happens here. + Boxstarter finished My First Section 00:00:00.2074282 Note that the number of '+' chars indicate nesting level. .LINK http://boxstarter.org Start-TimedSection about_boxstarter_logging #> param([string]$SectionId) $timerEntry=$script:boxstarterTimers.$SectionId if(!$timerEntry){return} $padCars="".PadLeft($boxstarterTimers.Count,"+") $script:boxstarterTimers.Remove($SectionId) $stopwatch = $timerEntry.stopwatch Write-Host "Finished $($timerEntry.Title) $($stopwatch.Elapsed.ToString())" -ForegroundColor Cyan $stopwatch.Stop() } function Install-WindowsUpdate { <# .SYNOPSIS Downloads and installs updates via Windows Update .DESCRIPTION This uses the windows update service to search, download and install updates. By default, only critical updates are included and a reboot will be induced if required. .PARAMETER GetUpdatesFromMS If this switch is set, the default windows update server, if any, is bypassed and windows update requests go to the public Microsoft Windows update service. .PARAMETER AcceptEula If any update requires a Eula acceptance, setting this switch will accept the Eula and allow the update to be installed. .PARAMETER SuppressReboots Setting this switch will suppress a reboot in the event that any update requires one. .PARAMETER Criteria The criteria used for searching updates. The default criteria is "IsHidden=0 and IsInstalled=0 and Type='Software'" which is effectively just critical updates. .LINK http://boxstarter.org #> param( [switch]$getUpdatesFromMS, [switch]$acceptEula, [switch]$SuppressReboots, [string]$criteria="IsHidden=0 and IsInstalled=0 and Type='Software' and BrowseOnly=0" ) <# if(Get-IsRemote){ Invoke-FromTask @" Import-Module $($boxstarter.BaseDir)\boxstarter.WinConfig\Boxstarter.Winconfig.psd1 Install-WindowsUpdate -GetUpdatesFromMS:`$$GetUpdatesFromMS -AcceptEula:`$$AcceptEula -SuppressReboots -Criteria "$Criteria" "@ -IdleTimeout 0 -TotalTimeout 0 if(Test-PendingReboot){ Invoke-Reboot } return } #> try{ $searchSession=Start-TimedSection "Checking for updates..." $updateSession =new-object -comobject "Microsoft.Update.Session" $Downloader =$updateSession.CreateUpdateDownloader() $Installer =$updateSession.CreateUpdateInstaller() $Searcher =$updatesession.CreateUpdateSearcher() if($getUpdatesFromMS) { $Searcher.ServerSelection = 2 #2 is the Const for the Windows Update server } $wus=Get-WmiObject -Class Win32_Service -Filter "Name='wuauserv'" $origStatus=$wus.State $origStartupType=$wus.StartMode Write-warning "Update service is in the $origStatus state and its startup type is $origStartupType." -verbose if($origStartupType -eq "Auto"){ $origStartupType = "Automatic" } if($origStatus -eq "Stopped"){ if($origStartupType -eq "Disabled"){ Set-Service wuauserv -StartupType Automatic } Write-Host "Starting windows update service..." -ForegroundColor Cyan Start-Service -Name wuauserv } else { # Restart in case updates are running in the background Write-Host "Restarting windows update service..." -ForegroundColor Cyan Restart-Service -Name wuauserv -Force -WarningAction SilentlyContinue } $Result = $Searcher.Search($criteria) Stop-TimedSection $searchSession $totalUpdates = $Result.updates.count If ($totalUpdates -ne 0) { Write-Host "$($Result.updates.count) Updates found." -ForegroundColor Magenta $currentCount = 0 foreach($update in $result.updates) { ++$currentCount if(!($update.EulaAccepted)){ if($acceptEula) { $update.AcceptEula() } else { Write-host " * $($update.title) has a user agreement that must be accepted. Call Install-WindowsUpdate with the -AcceptEula parameter to accept all user agreements. This update will be ignored." -ForegroundColor Yellow continue } } $Result= $null if ($update.isDownloaded -eq "true" -and ($update.InstallationBehavior.CanRequestUserInput -eq $false )) { Write-Host " * $($update.title) already downloaded" -ForegroundColor Green $result = install-Update $update $currentCount $totalUpdates } elseif($update.InstallationBehavior.CanRequestUserInput -eq $true) { Write-Host " * $($update.title) Requires user input and will not be downloaded." -ForegroundColor Yellow } else { Download-Update $update $result = Install-Update $update $currentCount $totalUpdates } } if($result -ne $null -and $result.rebootRequired) { if($SuppressReboots) { Write-Host "A Restart is Required." -ForegroundColor Yellow } else { $Rebooting=$true Write-Host "Restart Required. Restarting now..." -ForegroundColor Yellow Stop-TimedSection $installSession if(test-path function:\Invoke-Reboot) { return Invoke-Reboot } else { Restart-Computer -force } } } } else{Write-Host "There is no update applicable to this machine." -ForegroundColor Yellow} } catch { Write-Host "There were problems installing updates: $($_.ToString())." -ForegroundColor Red throw } finally { if($origAUVal){ Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU -Name UseWuServer -Value $origAUVal -ErrorAction SilentlyContinue } if($origStatus -eq "Stopped") { Write-Host "Stopping win update service and setting its startup type to $origStartupType." -ForegroundColor Yellow Set-Service wuauserv -StartupType $origStartupType stop-service wuauserv -WarningAction SilentlyContinue } } } function Download-Update($update) { $downloadSession=Start-TimedSection "Download of $($update.Title)" $updates= new-Object -com "Microsoft.Update.UpdateColl" $updates.Add($update) | out-null $Downloader.Updates = $updates $Downloader.Download() | Out-Null Stop-TimedSection $downloadSession } function Install-Update($update, $currentCount, $totalUpdates) { $installSession=Start-TimedSection "Install $currentCount of $totalUpdates updates: $($update.Title)" $updates= new-Object -com "Microsoft.Update.UpdateColl" $updates.Add($update) | out-null $Installer.updates = $Updates try { $result = $Installer.Install() } catch { if(!($SuppressReboots)){ Restart-Computer -force } # Check for WU_E_INSTALL_NOT_ALLOWED if($_.Exception.HResult -eq -2146233087) { Write-Host "There is either an update in progress or there is a pending reboot blocking the install." -ForegroundColor Yellow $global:error.RemoveAt(0) } else { throw } } Stop-TimedSection $installSession return $result } if ([string]::IsNullOrEmpty($PSScriptRoot)) { $PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition } $Wow6432Node = "" ; if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") { $Wow6432Node = "Wow6432Node" } try { Clear-Host Write-Host "Installing App-V pre-reqs..." -ForegroundColor Magenta if (([environment]::OSVersion.Version.Major -eq 10)) { if (-not (Test-Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5')) { Write-Host "Win10 detected, let's only enable NetFx3...." -ForegroundColor Yellow try { DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:$PSScriptRoot Write-host ".Net3.5 installed." -ForegroundColor Green } catch { Write-Warning ".Net3.5 failed to install." } } else {write-host "NetFx3 allready installed." -ForegroundColor Green} } else { if (-not (Test-Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5')) { try { $NetFx3 = (Join-Path $PSScriptRoot "dotnetfx35.exe") if(-not (Test-Path $NetFx3)) { Write-Host ".Net3.5 source not found, let's download..." -ForegroundColor Yellow Download-File -url "http://download.microsoft.com/download/6/0/f/60fc5854-3cb8-4892-b6db-bd4f42510f28/dotnetfx35.exe" -localFile $NetFx3 } Write-Host "Installing .Net3.5 ..." -ForegroundColor Cyan Start-Process -FilePath `"$NetFx3`" -ArgumentList "/q /norestart" -Wait | Out-Null Write-host ".Net3.5 installed." -ForegroundColor Green } catch { Write-Warning ".Net3.5 failed to install." } } else {write-host ".Net3.5 allready installed." -ForegroundColor Green} if (-not (Test-Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.6')) { try { $NetFx4 = (Join-Path $PSScriptRoot "NDP46-KB3045557-x86-x64-AllOS-ENU.exe") if(-not (Test-Path $NetFx4)) { Write-Host ".Net4.6 source not found, let's download..." -ForegroundColor Yellow Download-File -url "https://download.microsoft.com/download/C/3/A/C3A5200B-D33C-47E9-9D70-2F7C65DAAD94/NDP46-KB3045557-x86-x64-AllOS-ENU.exe" -localFile $NetFx4 } Write-Host "Installing .Net4.6..." -ForegroundColor Cyan Start-Process -FilePath `"$NetFx4`" -Wait | Out-Null Write-host ".Net4.6 installed." -ForegroundColor Green } catch { Write-Warning ".Net4.6 failed to install." } } else {write-host ".Net4.6 allready installed." -ForegroundColor Green} if ($host.version.Major -le 3) { try { If ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") { $WMF4 = (Join-Path $PSScriptRoot "Windows6.1-KB2819745-x64-MultiPkg.msu") if(-not (Test-Path $WMF4)) { Write-Host ".WMF4x64 source not found, let's download..." -ForegroundColor Yellow Download-File -url "https://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x64-MultiPkg.msu" -localFile $WMF4 } } else { $WMF4 = (Join-Path $PSScriptRoot "Windows6.1-KB2819745-x86-MultiPkg.msu") if(-not (Test-Path $WMF4)) { Write-Host ".WMF4x86 source not found, let's download..." -ForegroundColor Yellow Download-File -url "https://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x86-MultiPkg.msu" -localFile $WMF4 } } Write-Host "Installing WMF4 ..." -ForegroundColor Cyan Start-Process -FilePath wusa.exe -ArgumentList `"$WMF4`", "/quiet", "/norestart" -Wait | Out-Null Write-host "WMF4 installed." -ForegroundColor Green } catch { Write-Warning "WMF4 failed to install." } } else {write-host "WMF4 or higher allready installed." -ForegroundColor Green} } Write-Host "Disabling automatic Windows Updates..." -ForegroundColor Cyan New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" -Name AUOptions -PropertyType DWord -Value 1 -Force | Out-Null if (([environment]::OSVersion.Version.Major -eq 6 -and [environment]::OSVersion.Version.Minor -gt 1) -or ([environment]::OSVersion.Version.Major -gt 6)) { Write-Host "Disabling automatic Windows Store Updates..." -ForegroundColor Cyan New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsStore\WindowsUpdate" -Name AutoDownload -PropertyType DWord -Value 2 -Force | Out-Null } if (Test-Connection -ComputerName 2001:4860:4860::8888 -Count 3 -ErrorAction SilentlyContinue) # ping google for internet { Enable-MicrosoftUpdate try {Install-WindowsUpdate -Criteria "IsHidden=0 and IsInstalled=0 and Type='Software'" } catch { Install-WindowsUpdate -Criteria "IsHidden=0 and IsInstalled=0 and Type='Software'" } } Set-Service wuauserv -StartupType Disabled Write-Host "Disabling Security Center..." -ForegroundColor Cyan Set-Service -Name wscsvc -StartupType Disabled if ([environment]::OSVersion.Version.Major -lt 10) { New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name HideSCAHealth -PropertyType DWord -Value 1 -Force | Out-Null } else { if (!(Test-Path -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer")) { New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer" | Out-Null } New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer" -Name DisableNotificationCenter -PropertyType DWord -Value 1 -Force | Out-Null } Write-Host "Disabling System Restore..." -ForegroundColor Cyan Disable-ComputerRestore -Drive "C:\" Start-Process -FilePath vssadmin -ArgumentList "delete shadows /for=c: /all /quiet" -Wait | Out-Null Write-Host "Peforming SSD optimisations..." -ForegroundColor Cyan Set-Service -Name SysMain -StartupType Disabled New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters" -Name EnableSuperfetch -PropertyType DWord -Value 0 -Force | Out-Null New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters" -Name EnablePrefetcher -PropertyType DWord -Value 0 -Force | Out-Null New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\WMI\Autologger\ReadyBoot" -Name Start -PropertyType DWord -Value 0 -Force | Out-Null Write-Host "Disabling computer password change..." -ForegroundColor Cyan New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\NetLogon\Parameters" -Name DisablePasswordChange -PropertyType DWord -Value 1 -Force | Out-Null Write-Host "Configuring power options..." -ForegroundColor Cyan powercfg -change -monitor-timeout-ac 0 powercfg -change -standby-timeout-ac 0 powercfg -h off Write-Host "Enabling Remote Desktop..." -ForegroundColor Cyan $oTS = Get-WmiObject -Class "Win32_TerminalServiceSetting" -Namespace root\cimv2\terminalservices if($oTS -eq $null) { Write-host "Unable to locate terminalservices namespace. Remote Desktop is not enabled." -ForegroundColor Red } try { $oTS.SetAllowTsConnections(1,1) | out-null } catch { Write-host "There was a problem enabling remote desktop. Make sure your operating system supports remote desktop and there is no group policy preventing you from enabling it." -ForegroundColor Red } Write-Host "Configuring Windows Explorer options..." -ForegroundColor Cyan Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowFileExtensions If ([environment]::OSVersion.Version.Major -eq 6 -and [environment]::OSVersion.Version.Minor -gt 1) { Set-StartScreenOptions -EnableBootToDesktop -EnableDesktopBackgroundOnStart -EnableShowStartOnActiveScreen -EnableShowAppsViewOnStartScreen -EnableSearchEverywhereInAppsView -EnableListDesktopAppsFirst } Write-Host "Pinning taskbar shortcuts..." -ForegroundColor Cyan Install-PinnedTaskBarItem "${env:ProgramFiles(x86)}\Internet Explorer\iexplore.exe" Install-PinnedTaskBarItem "$env:windir\System32\cmd.exe" Install-PinnedTaskBarItem "$env:windir\System32\WindowsPowerShell\v1.0\powershell.exe" Install-PinnedTaskBarItem "$env:windir\regedit.exe" Install-PinnedTaskBarItem "$env:windir\Notepad.exe" Install-PinnedTaskBarItem "$env:windir\System32\SnippingTool.exe" Write-Host "Configuring Internet Explorer..." -ForegroundColor Cyan if(Test-Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}") { Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" -Name "IsInstalled" -Value 0 } if(Test-Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}") { Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}" -Name "IsInstalled" -Value 0 } New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main" -Name DisableFirstRunCustomize -PropertyType DWord -Value 1 -Force | Out-Null New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Internet Explorer\Main" -Name "Start Page" -PropertyType String -Value "about:blank" -Force | Out-Null Restart-Explorer Write-host "IE Enhanced Security Configuration (ESC) has been disabled." -ForegroundColor Green if (Get-Process "OneDrive" -ErrorAction SilentlyContinue) { Write-Host "Removing OneDrive..." -ForegroundColor Cyan Start-Process -FilePath "taskkill.exe" -ArgumentList "/f /im OneDrive.exe" -Wait | Out-Null Start-Process -FilePath "C:\Windows\SysWOW64\OneDriveSetup.exe" -ArgumentList "/uninstall" -Wait | Out-Null Set-ItemProperty -Path "HKCU:\Software\classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" -Name "System.IsPinnedToNameSpaceTree" -Value 0 -Force | Out-Null } Write-Host "Setting up App-V Sequencer build..." -ForegroundColor Magenta Write-Host "Disabling UAC..." -ForegroundColor Cyan New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\policies\system" -Name EnableLUA -PropertyType DWord -Value 0 -Force | Out-Null Write-Host "Disabling Windows Defender..." -ForegroundColor Cyan if ([environment]::OSVersion.Version.Major -eq 6 -and [environment]::OSVersion.Version.Minor -lt 2) { Set-Service -Name WinDefend -StartupType Disabled } else { New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender" -Name "DisableAntiSpyware" -PropertyType dword -Value 1 -Force | Out-Null } if (Get-Service CCmExec -ErrorAction SilentlyContinue) { Write-Host "Disabling SMS agent host..." -ForegroundColor Cyan Set-Service -Name WSearch -StartupType Disabled } Write-Host "Disabling Windows Search..." -ForegroundColor Cyan Set-Service -Name WSearch -StartupType Disabled Write-Host "Disabling FontCache..." -ForegroundColor Cyan Set-Service -Name FontCache3.0.0.0 -StartupType Disabled Write-Host "Disabling Sheduled Tasks..." -ForegroundColor Cyan schtasks /change /tn "\Microsoft\Windows\Application Experience\AitAgent" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\Application Experience\ProgramDataUpdater" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\AutoChk\Proxy" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\Customer Experience Improvement Program\Consolidator" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\Customer Experience Improvement Program\KernelCeipTask" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\Customer Experience Improvement Program\UsbCeip" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\Defrag\ScheduledDefrag" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\Diagnosis\Scheduled" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticDataCollector" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticResolver" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\Maintenance\WinSAT" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\Power Efficiency Diagnostics\AnalyzeSystem" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\RAC\RacTask" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\Registry\RegIdleBackup" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\Windows Error Reporting\QueueReporting" /disable | Out-Null schtasks /change /tn "\Microsoft\Windows\Windows Media Sharing\UpdateLibrary" /disable | Out-Null Write-Host "Creating dummy ODBC keys..." -ForegroundColor Cyan New-Item -Path "HKCU:\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources" -Force | Out-Null New-Item -Path "HKLM:\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources" -Force | Out-Null if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") { New-Item -Path "HKLM:\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\ODBC Data Sources" -Force | Out-Null } if (-not ($SeqVersion = (Get-command "C:\Program Files\Microsoft Application Virtualization\Sequencer\Sequencer.exe" -ErrorAction SilentlyContinue).FileVersionInfo.ProductVersion)) { try { $Sequencer = (Join-Path $PSScriptRoot "appv_sequencer_setup.exe") if(-not (Test-Path $Sequencer)) { Write-Host "Sequencer source not found, please download and run the script again..." -ForegroundColor Red } else { Write-Host "Installing sequencer..." -ForegroundColor Cyan Start-Process -FilePath `"$Sequencer`" -ArgumentList "/ACCEPTEULA /q" -Wait | Out-Null Write-host "Sequencer installed." -ForegroundColor Green Install-PinnedTaskBarItem "$env:ProgramFiles\Microsoft Application Virtualization\Sequencer\Sequencer.exe" } } catch { Write-Warning "Sequencer failed to install." } } else {write-host "Sequencer $SeqVersion allready installed." -ForegroundColor Green} if (-not (Test-Path "HKLM:\SOFTWARE\$Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{A79B1F5E-FEC1-4DD7-86F3-7EB2ED1D28F2}")) { try { $ACE = (Join-Path $PSScriptRoot "ACE.msi") if(-not (Test-Path $ACE)) { Write-Host "ACE source not found, let's download..." -ForegroundColor Yellow Download-File -url "http://virtualengine.co.uk/?wpdmdl=3800" -localFile $ACE } Write-Host "Installing ACE ..." -ForegroundColor Cyan Start-Process -FilePath msiexec.exe -ArgumentList /i, `"$ACE`", RUNAPPLICATION=0, AI_QUICKLAUNCH_SH=1, AI_STARTMENU_SH=0, AI_STARTUP_SH=0, /qn -Wait | Out-Null Install-PinnedTaskBarItem "${env:ProgramFiles(x86)}\Virtual Engine\ACE\Ace.exe" Write-host "ACE installed." -ForegroundColor Green } catch { Write-Warning "ACE failed to install." } } else {write-host "ACE allready installed." -ForegroundColor Green} Write-Host "Add 'Copy as Path' Shellhandler..." -ForegroundColor Cyan Set-Location -LiteralPath "HKLM:\SOFTWARE\Classes\*\shell" | Out-Null New-Item . -Name "Copy as Path" -Force | Out-Null Set-Location -LiteralPath "HKLM:\SOFTWARE\Classes\*\shell\Copy as Path\" | Out-Null New-Item . -Name "command" -Value 'cmd.exe /c echo \"%1\"|clip' -Force | Out-Null New-Item -Path "HKLM:\SOFTWARE\Classes\Directory\shell" -Name "Copy as Path" -Force | Out-Null New-Item -Path "HKLM:\SOFTWARE\Classes\Directory\shell\Copy as Path" -Name "command" -Value 'cmd.exe /c echo \"%1\"|clip' -Force | Out-Null Set-Location $PSScriptRoot Write-Host "Optimising .NET assemblies..." -ForegroundColor Cyan Start-Process -FilePath "C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe" -ArgumentList "executeQueuedItems /nologo /silent" -Wait if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") { Start-Process -FilePath "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" -ArgumentList "executeQueuedItems /nologo /silent" -Wait } Write-Host "Performing disk clean up..." -ForegroundColor Cyan New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin" -Name "StateFlags0001" -PropertyType dword -Value 2 -Force | Out-Null New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Update Cleanup" -Name "StateFlags0001" -PropertyType dword -Value 2 -Force | Out-Null Start-Process cleanmgr.exe -ArgumentList "/sagerun:1" -Wait Remove-Item $env:temp\* -Force -Recurse Remove-Item C:\Windows\Temp\* -Force -Recurse #Zero unused sectors to allow VHD to be compacted efficiently with Optimize-VHD cmdlet $env:SEE_MASK_NOZONECHECKS = 1 if (Test-Path (Join-Path $PSScriptRoot "sdelete.exe")) { Start-Process -FilePath (Join-Path $PSScriptRoot "sdelete.exe") -ArgumentList "-AcceptEula -s -z c:" -Wait } elseif (Test-Path "\\live.sysinternals.com\tools\sdelete.exe") { Start-Process -FilePath "\\live.sysinternals.com\tools\sdelete.exe" -ArgumentList "-AcceptEula -s -z c:" -Wait } else { Write-Warning "Unable to run sysinternals sdelete.exe..." } } catch { Write-Warning $($_.Exception.Message) throw } do { $choice = Read-Host -Prompt "Reboot now? [y/n]" If ($choice -eq "y") { Write-Host "restarting now..." -ForegroundColor Green;Restart-Computer -Force} If ($choice -eq "n") { Write-Host "Reboot first, and start your Sequence." -ForegroundColor Green} } until ($choice)

Hope it Helps ,

Kenny Buntinx & Roy Essers

Configmgr 2012 : Broken Applications in your task sequences after an upgrade (error 615)

1:08 pm in 615, Application Model, applications, CM12, CM12 R2, CM12 R2 SP1, CM12 SP1, CM12 SP2, ConfigMgr 2012, configmgr 2012 R2, ConfigMgr 2012 R2 SP1, ConfigMgr 2012 SP1, ConfigMgr SP2, coretech, err, error 615, OSD, SCCM 2012, sccm 2012 R2, SCCM 2012 R2, SCCM 2012 R2 SP1, SCCM 2012 SP1, troubleshooting, xmasblogroll by Kenny Buntinx [MVP]

 

Scenario: Upgrading a Configmgr 2012 RTM/SP1/R2 environment to a new R2 SP1 environment will end up into broken applications in your Task sequences with error 615 in the status messages.

Issue: After the upgrade was successfully performed , suddenly all applications within my OSD task sequence start failing with the following error code :

The task sequence failed to install application Intel Management Engine 6.0.40.1215(ScopeId_67A221E3-64F0-47D4-AA5A-BB3729EC221F/Application_2071f753-7604-42a5-b6be-b1b45c3c1f0a) for action (Install HW Driver Applications for HP8540P) in the group () with exit code 615. The operating system reported error 615: The password provided is too short to meet the policy of your user account. Please choose a longer password.

clip_image002

To be honest with my blog readers, this particular message can be caused by multiple reasons. I will list all possible solutions / workarounds that I have come across to solve this issue.

Cause 1 – Applications have no ContentID associated:

I blogged about this beginning of 2013 at http://scug.be/sccm/2013/01/08/configmgr-2012-sp1-broken-applications-after-upgrading-from-rtm/

After some checks, I saw that it concerned only applications and I discovered that had no ContentID associated to each Deployment Type. In other words, all the applications created and that are embedded in a TS with no direct deployments attached to the Application. It appears that the upgrade process broke all applications.

You can confirm this with the Application Catalog downloads as well. You will see “+++ Did not detect app deployment type”… in the AppDiscovery.log file. Additionally, the Software Center will show the error message “Failed”. Clicking on the details will result in “The software change returned error code 0x87D00607(-2016410105).”

We found as workaround, you have simply to add a comment to each DT and it will update the content ID. Nevertheless, the change means that a redistribution of your application on all your DP’s.

Following the steps as further discussed in this blog post at http://scug.be/sccm/2013/01/27/configmgr-2012-sp1-powershell-script-to-repair-broken-applications-after-upgrading-them-from-rtm/, the application will successfully install afterwards.

Cause 2 – Corrupt task sequence:

In some cases the policy that is related to the task sequence gets corrupt. This can be easily solved by creating a brand new task sequence and copying the steps from the older one side-by-side. Delete the old task sequence & create a new deployment for the just newly created task sequence.

Cause 3 – SMSMP parameter set incorrect:

I had also had problems after upgrading to SCCM R2 SP1. I was not able to install any applications as part of a task sequence as they all failed with error 615 or error 0x80004005. Installing applications outside of a Task sequence did work normally. The status message reported was exactly the same as described above "615 Password too short".

After investigating the client side log files it turned out, that the SCCM client was trying to download the application package using https first and after a few retry’s would switch to http only.

Because my DP is configured to accept http and https as like default behavior. I fixed the Problem by changing the value of the SMSMP parameter in the Task sequence step "Setup Windows and Configuration Manager" from

SMSMP=myserver.mydomain.local

to this:

SMSMP=http://myserver.mydomain.local

After this change, application installation worked as expected again.

clip_image004

Cause 4 – FIPS has been enabled :

Enabling FIPS mode makes Windows and its subsystems use only FIPS-validated cryptographic algorithms. An example is Schannel, which is the system component that provides SSL and TLS to applications. When FIPS mode is enabled, Schannel disallows SSL 2.0 and 3.0, protocols that fall short of the FIPS standards. Applications such as web browsers that use Schannel then cannot connect to HTTPS web sites that don’t use at least TLS 1.0. (Note that the same results can be achieved without FIPS mode by configuring Schannel according to KB 245030 and this blog post.)

Enabling FIPS mode also causes the .NET Framework to disallow the use of non-validated algorithms.

Microsoft advises not to use FIPS anymore as shown in the screenshot below : http://blogs.technet.com/b/secguide/archive/2014/04/07/why-we-re-not-recommending-fips-mode-anymore.aspx

clip_image006

In our case this solved the issue with the error 615. Probably it was a combination of things , but this is certainly something to disable and try.

Cause 5 – Use the latest CU2 on CM12 R2 SP1 :

Always make sure to use the latest CU’s as they include important fixes . You can download CU2 over here : https://support.microsoft.com/en-us/kb/3100144#/en-us/kb/3100144

The two most important fixes that may help to avoid error 615 in CU2 for R2 SP1 are :

– Applications will not install when you use them with a dynamic variable list in a task sequence if no SMB package share was defined for the content. This affects only installations that use a dynamic variable list. Other installation methods are unaffected.

No Http location found
Failed to download content for SMS package PRI00080, hr=0x80004005
Install Dynamic software action failed to resolve content for packageID: ‘PRI00080′, programID: ‘TestApp’. Error Code 0x80004005

– In a Configuration Manager environment in which multiple certificates are deployed to client computers, the client may select the wrong certificate for use in management point communication. This occurs when one certificate is based on a version 2 template and one is based on version 3. The client will select the certificate that has the longest validity period. This may be the version 3 certificate, and this certificate may not be currently supported by Configuration Manager. Errors that resemble the following are recorded in the ClientIDManagerStartup.log file.

[RegTask] – Executing registration task synchronously.
RegTask: Failed to create registration request body. Error: 0x80090014

 

Hope it Helps ,

Kenny Buntinx

MVP Enterprise Mobility

SCCM 2012 : “Another Installation is already in Progress” when deploying Applications thru OSD deployment.

11:26 am in agent, Application Model, applications, ConfigMgr 2012, configmgr 2012 R2, ConfigMgr 2012 SP1, OSD, SCCM 2012, SCCM 2012 R2, SCCM 2012 SP1, Task Sequence by Kenny Buntinx [MVP]

 

At one of my current customers, I have been stuck for two days now, that one or two randomly selected applications where failing If we looked in the ‘Status Messages’ and dig al little deeper , we saw in there that :

‘Another installation is already in progress.Complete that installation before proceeding with this install.’

 image

Knowing this is a highly secured environment , my first guess would be policies. However I overruled this thinking strategy because during the OSD process , GPO’s aren’t applied …—> That is a fact , except for one scenario I already blogged about it as described here  ‘http://scug.be/sccm/2013/02/13/configmgr-2012-rtmsp1-applications-failed-to-install-during-osd-with-error-code-16389-and-denied-logon-for-domain-users-policy/’ , but that was not the issue…

Back to the drawing board and digging deeper in the smstslog file … Suddenly when hitting the F8 button a popup arrived that I needed a reboot to complete the “Kaspersky Antimalware Client”  … WTF is that doing in my task sequence.

Apparently someone at the customer decided to set a policy at the Kaspersky management server , to Push / Install a Kaspersky client when he detects and scans the network for computers that did not had a Kaspersky mgmt. agent installed. That little process hijacked my Task sequence installation process and jumped in the middle to install that Kaspersky agent .

Case Closed …My advise – before troubleshooting Configmgr , just start asking questions who did changes on other parts of the environment Emoticon die tong uitsteekt

Hope it Helps ,

Kenny Buntinx

Enterprise Client Management MVP

Configmgr 2012 SP1 : PowerShell Script to repair “Broken Applications after upgrading them from RTM”

7:52 pm in Application Model, applications, CM12, ConfigMgr, ConfigMgr 2012, ConfigMgr 2012 SP1, Deployment, deployment types, SCCM 2012, SCCM 2012 SP1, upgrade by Kenny Buntinx [MVP]

 

Upgrading a Configmgr 2012 RTM environment to a new SP1 environment . After the upgrade was successfully performed , suddenly all applications within my OSD task sequence start failing as described in my previous blog post here : http://scug.be/sccm/2013/01/08/configmgr-2012-sp1-broken-applications-after-upgrading-from-rtm/

Finally we have found some other errors as well , they are listed here :

  • The task sequence failed to install application Intel Management Engine 6.0.40.1215(ScopeId_67A221E3-64F0-47D4-AA5A-BB3729EC221F/Application_2071f753-7604-42a5-b6be-b1b45c3c1f0a) for action (Install HW Driver Applications for HP8540P) in the group () with exit code 615. The operating system reported error 615: The password provided is too short to meet the policy of your user account. Please choose a longer password.
  • The task sequence failed to install application NVIDIA Quadro/NVS Mobile Drivers 305.93(ScopeId_67A221E3-64F0-47D4-AA5A-BB3729EC221F/Application_17e0153e-3d4f-467b-a2b3-68491516b0e1) for action (Install HW Driver Applications for HP8540P) in the group () with exit code 580. The operating system reported error 580: An event pair synchronization operation was performed using the thread specific client/server event pair object, but no event pair object was associated with the thread.
  • The task sequence failed to install application Synaptics Touch Pad Driver(ScopeId_67A221E3-64F0-47D4-AA5A-BB3729EC221F/Application_a0628bfc-3f06-4096-a001-c1a6c92675ea) for action (Install HW Driver Applications for HP8540P) in the group () with exit code 16389. The operating system reported error 2: The system cannot find the file specified.

We found a workaround, you have simply to add a comment to each DT and it will update the content ID. Nevertheless, the change means that a redistribution of your application on all your DP’s.

BUT , that is all manual work , and we hate that , don’t we Smile with tongue out . Luckily we have an excellent PowerShell scripter in our team and all credits for creating this script goes to  Bart Serneels. He has written a PowerShell script to do all the work . He was happy to share this with you guys.

Here is the script : (replace VVM with your “Site Code” )

 

What the script will do is :

  1. Look for any application that has no deployment attached to it
  2. Opens the application deployment type(s) and looks for a description .
  3. If the description field is empty , it will update that field with the deployment type name.
  4. If the description field exists , it will make a backup , adapt it with the deployment type name , save it , reopen and revert to the backup descriptions and save it once more .

Again  , this is a workaround that helped us fixing our issues and no guarantee it will work for you .

Hope it Helps ,

Kenny Buntinx

MVP ConfigMgr

Configmgr 2012 SP1 : Broken Applications after upgrading from RTM

10:45 am in a, Application Model, applications, ConfigMgr, ConfigMgr 2012, ConfigMgr 2012 SP1, SCCM 2012, SCCM 2012 SP1, upgrade by Kenny Buntinx [MVP]

Scenario : Upgrading a Configmgr 2012 RTM environment to a new SP1 environment . It was a standalone primary site RTM Build without any CU (5.00.7711.0000).

Issue : After the upgrade was successfully performed , suddenly all applications within my OSD task sequence start failing with the following error code :

The task sequence failed to install application Intel Management Engine 6.0.40.1215(ScopeId_67A221E3-64F0-47D4-AA5A-BB3729EC221F/Application_2071f753-7604-42a5-b6be-b1b45c3c1f0a) for action (Install HW Driver Applications for HP8540P) in the group () with exit code 615. The operating system reported error 615: The password provided is too short to meet the policy of your user account. Please choose a longer password.

Identifying the cause:  After some checks, I saw that it concerned only applications and I discovered that had no ContentID associated to each Deployment Type. In other words, all the applications created and that are embedded in a TS with no direct deployments attached to the Application.  It appears that the upgrade process broke all applications.

Workaround :

We found a workaround, you have simply to add a comment to each DT and it will update the content ID. Nevertheless, the change means that a redistribution of your application on all your DP’s.

Hope it Helps ,

Kenny Buntinx

Configmgr 2012 RTM/SP1 Part 1: Not so basic Applications and there Detection Methods

2:44 pm in Application Model, applications, ConfigMgr, ConfigMgr 2012, ConfigMgr 2012 SP1, Deployment, deployment types, detection methods, sccm, SCCM 2012, SCCM 2012 SP1, vbscript by Kenny Buntinx [MVP]

 

Hi Guys ,

I will start a series of blog posts that will list all common applications with requirements and dependencies you need to build your general OSD Task Sequence.

Today I will start with 2 great examples such as :

  1. Installing a or multiple certificate(s) for SCUP 2011 which is using a registry key as detection method
  2. Internet explorer 9 Post install hotfix which is using a script as detection method

Scenario 1 :

So let’s start with the first example , being certificate deployment as an application in a  task sequence :

Let’s ask ourselves first this question : Why would we use an application to deploy certificates during an OSD deployment if we have Group Policy Object to do it for us ? Well , the answer is :  This Microsoft document at: http://technet.microsoft.com/en-us/library/bb693951.aspx states that "The Setup Windows and ConfigMgr” task sequence action is responsible for running Group Policy on the newly installed computer. At which point during the task sequence action that Group Policy is applied depends on the operating system being deployed. On Windows XP and Windows Server 2003, Group Policy runs after the task sequence is finished, the task sequence GINA has been unloaded and then replaced with the GINA on Windows. On Windows Vista and Windows Server 2008, Group Policy runs after the Setup Windows and ConfigMgr task sequence action completes. "

Let’s build our Application now :

1. Export your self signed certificate , and place it in a source folder . For Windows 7 , you don’t need any additional tooling , for XP you do. You need “certutilxp.exe and certadm.dll”

image

2. Create 2 batch files :

Install.cmd –> For Win7

SNAGHTML105afa45

Install_XP.cmd –> For XP

image

3. Create your application . In this example “ WSUS Self Signed Certificate”

SNAGHTML10537a2a

4. Create 2 deployment types . One for XP and one for Win7 .

SNAGHTML1056340b

5. On the “Detection Method” tab , specify a registry key

In my case : HKLM\SOFTWARE\Microsoft\SystemCertificates\TrustedPublisher\Certificates\6BFF5439A57586FEF61B8D8E2194A96DD459B511 and HKLM\SOFTWARE\Microsoft\SystemCertificates\AuthRoot\Certificates\6BFF5439A57586FEF61B8D8E2194A96DD459B511

image

Where does the “6BFF5439A57586FEF61B8D8E2194A96DD459B511” value comes from ? It will come from the properties of your exported certificate.

Take the properties of your certificate and take a look at the value “ Thumbprint” as shown below :

SNAGHTML10644ee2

6. Define your requirement here directly or with a global condition :

SNAGHTML10661df4

7. Your done !

Scenario 2 : Internet explorer 9 Post install hotfix

So let’s start with the second example , being an Internet explorer 9 fix  deployment as an application in a  task sequence :

Why ? I was looking at several Windows 7 machines in an environment that whenever a new domain user who had never logged onto a machine before got the following error message:

The User Profile Service service failed the logon.

User profile cannot be loaded.

image

Now in this case there was an existing Microsoft KB article for this located here http://support.microsoft.com/kb/947215

Let’s build our Application now :

1. Create a VBS with the following lines :

image

 

2.  Create your application . In this example “ Internet Explorer 9 Post Install Fix”

SNAGHTML10727ca4

3. Create a deployment type.

image

4. Specify your Program to run . In this case “IE9….vbs”

SNAGHTML1074c859

5. Now we will use a script as detection method . If the exit code is a non-zero value, then the script has failed and the application detection status is unknown. If the exit code is zero and STDOUT contains data then the application detection state is installed. –> see http://technet.microsoft.com/en-us/library/b2483e0f-3b9b-4551-ba5e-19fe0f5be3be#BKMK_Step4

From my experience, if you use a vbscript method of detection; any returned value from wscript.echo, anything at all, means that the detection passed.  Even if you wscript.echo "FALSE", it doesn’t matter; something was returned, the script passed.

If you don’t want it to pass detection, simply don’t echo anything.

SNAGHTML1075574b

6. We specify VBScript as language and past a script to detect if the file is there or not .

SNAGHTML107627f9

 

Hope it Helps ,

Kenny Buntinx