Software Center – Application / Task Sequence stuck on Installing

Run Powershell Elevated

Are you seeing task sequences enter invalid states? 

gwmi -Namespace root\ccm\SoftMgmtAgent -Class CCM_TSExecutionRequest -Filter "State = 'Completed' And CompletionState = 'Failure'"

Clear the entry

$c=(gwmi -Namespace root\ccm\SoftMgmtAgent -Class CCM_TSExecutionRequest -Filter "State = 'Completed' And CompletionState = 'Failure'"); if ($c) {$c.Delete(); Restart-Service ccmexec -force}

or

Start CMD as an Administrator

net stop winmgmt /y

winmgmt /resetrepository

reboot PC

Start CMD as an Administrator

c:\windows\ccm\ccmrepair.exe

Remove HKCU registry entries of multiple users

$Users = (Get-ChildItem -path c:\users).name
foreach ($User in $Users) {
    reg load "hku\$User" "C:\Users\$User\NTUSER.DAT"
    # Do what you need with "hkey_users\$user" here which links to that user HKU
    # Example: reg add "hkey_users\$User\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People" /v "PeopleBand" /t "REG_DWORD" /d "0" /f
    REG DELETE "hkey_users\$User\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "OneDrive" /f
    REG DELETE "hkey_users\$User\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "com.squirrel.Teams.Teams" /f
    reg unload "hku\$User"
}

Note: Current users logged on the system will be not affected because the ntuser.dat file is locked by the system.

Stop & Disable Service

$Services = Get-Service -DisplayName "*Citrix *"

Foreach ($Service in $Services)
{
    Stop-Service -Name ($Service).Name
    Set-Service -Name ($Service).Name -StartupType Disabled
}

Run MSI from PowerShell script with spaces in directories

Make use of double “” to add a single ” in a variable for paths that has spaces

C:\Program Files (x86)\ThunderBolt 3 Update

$ExportPath = ${Env:ProgramFiles(x86)} + "\ThunderBolt 3 Update"
Write-Log "Detecting Thunderbolt Driver Version"
$TBTDriverVersion = (Get-WmiObject Win32_PnPSignedDriver | Where-Object { $_.DeviceName -like "*Thunderbolt(TM) Controller*" }).driverversion
	if ($null -eq $TBTDriverVersion) {
		try {
                    Write-Log "Thunderbolt Driver not found"
                    $InstallCmd = "$ExportPath\SW\$CSVCMDSW"
                    $InstallCmdLog = "/l*v ""$ExportPath\Install_SW.log"""
                    $InstallCmdComplete = "/i ""$InstallCmd"" /qn"

                    Write-Log "Installing Thunderbolt Software"
                    $InstallTBTSoftware = Start-Process -FilePath msiexec.exe -ArgumentList $InstallCmdComplete -Wait 
                }                
                catch {
                    Write-Log "Thunderbolt Software installation failed "$InstallTBTSoftware.ExitCode". Logs located at $ExportPath"
                    Write-Log "----------------------------- End Script ------------------------------"
                    Exit
                }

GetLocalGroupsSID

$computerName = Read-Host ‘Enter computer name or press <Enter> for localhost’

$List = @{}

if ($computerName -eq “”) {$computerName = “$env:computername”}

$computer = [ADSI]”WinNT://$computerName,computer”

$Users = $computer.psbase.Children | Where-Object { $_.psbase.schemaclassname -eq ‘group’ }

foreach ($i in $Users)

{$objUser = New-Object System.Security.Principal.NTAccount($i.Name)

$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])

$list[$i.Name[0]] = $strSid.Value

}

$list | ft

Hyper-V VM Scripts

<#

ImportHyperVVM.ps1

Dries Willems

03/12/2014

#>

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V –All -NoRestart

Restart-Computer -Wait -For PowerShell -Timeout 600 -Delay 2

Import-Module Hyper-V

$ethernet = Get-NetAdapter -Name ethernet

$wifi = Get-NetAdapter -Name wi-fi

New-VMSwitch -Name EthernetExternalSwitch -NetAdapterName $ethernet.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, LAN’

New-VMSwitch -Name WiFiExternalSwitch -NetAdapterName $wifi.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, wifi’

Copy-Item * C:\VM

Import-VM -Path ‘C:\VM\Cobra\Virtual Machines\6FAEE0C5-7422-45BD-A915-AA3C3A5D06A7.XML’

$OldHostname = Get-WmiObject win32_computersystem | select-object -expandproperty name

$NewHostname = $OldHostname + “VM”

Rename-VM Cobra $NewHostname

Start-VM $NewHostname

———————————————————————————————

<#

RenameStartVM.ps1

Dries Willems

03/12/2014

#>

$OldHostname = Get-WmiObject win32_computersystem | select-object -expandproperty name

$NewHostname = $OldHostname + “VM”

Rename-VM Cobra $NewHostname

Start-VM $NewHostname

———————————————————————————————

<#

CreateVSwitchImportRenameStartCobra.ps1

Dries Willems

03/12/2014

#>

Import-Module Hyper-V

#Create Virtual Switch

$ethernet = Get-NetAdapter -Name ethernet

$wifi = Get-NetAdapter -Name wi-fi

New-VMSwitch -Name EthernetExternalSwitch -NetAdapterName $ethernet.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, LAN’

New-VMSwitch -Name WiFiExternalSwitch -NetAdapterName $wifi.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, wifi’

#Import VM

Import-VM -Path ‘C:\VM\Cobra\Virtual Machines\8F300942-505B-41C0-8644-B46321581214.XML’

#Rename VM & Start

$OldHostname = Get-WmiObject win32_computersystem | select-object -expandproperty name

$NewHostname = $OldHostname + “VM”

Rename-VM Cobra $NewHostname

Start-VM $NewHostname

——————————————————————————————–Cobra.bat

Powershell.exe -executionpolicy bypass -File .\CreateVSwitchImportRenameStartCobra.ps1

xcopy “C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Hyper-V Management Tools\VMConnect.lnk” “C:\Users\Public\Desktop\Hyper-V Virtual Machine Connection.lnk”* /I /S /Y /C /R

Change Statuscode 3010 to 0

@echo off

msiexec /I vc_red.msi TRANSFORMS=vc_red.mst /qn ALLUSERS=1 /L*v %windir%\temp\TEST_SDS_Microsoft_VC++RedistSU_2008SP1_1.0_EN_x86_Inst.log REBOOT=REALLYSUPPRESS

if %errorlevel% == 3010 (exit /b 0) else (exit /b %errorlevel%)

SetUsersFullControl.ps1

$sharepath = “C:\SWL”

$Acl = Get-ACL $SharePath

$AccessRule= New-Object System.Security.AccessControl.FileSystemAccessRule(“Users”,”full”,”ContainerInherit,Objectinherit”,”none”,”Allow”)

$Acl.AddAccessRule($AccessRule)

Set-Acl $SharePath $Acl