Saturday, December 24, 2016

App-V 5 : Remote Computer Refresh and Repair Shortcuts using Schedule Task



Powershell Script:

$computername = Read-Host "Enter Computer Name"
function Ping-Host {
  Param([string]$computername=$(Throw "You must specify a computername."))
 
  $query="Select * from Win32_PingStatus where address='$computername'"
 
  $wmi=Get-WmiObject -query $query
  write $wmi
}
$pingResult = Ping-Host $computername
if ($pingResult.StatusCode -eq 0) {

    $XMLPath = $PSScriptRoot + "\AppV_Refresh.xml"
    $XMLPath1 = $PSScriptRoot + "\AppV_Repair.xml"
    schtasks /create /s $computername /Xml $XMLPath /F /TN 'AppV_Refresh_Manual'
    Start-Sleep 10
    schtasks /delete /s $computername /F /TN 'AppV_Refresh_Manual'
    Start-Sleep 10
    schtasks /create /s $computername /Xml $XMLPath1 /F /TN 'AppV_Repair_Manual'
    Start-Sleep 10
    schtasks /delete /s $computername /F /TN 'AppV_Repair_Manual'

}
Else{
Write-Host "$computername is offline" -BackgroundColor Red
}

AppV_Refresh.xml:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2016-09-18T22:07:37</Date>
    <Author>CHALLAZ</Author>
    <URI>\AppV_Refresh_Manual</URI>
  </RegistrationInfo>
  <Triggers>
    <RegistrationTrigger>
      <EndBoundary>2020-01-01T00:00:00</EndBoundary>
      <ExecutionTimeLimit>PT30M</ExecutionTimeLimit>
      <Enabled>true</Enabled>
    </RegistrationTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <GroupId>S-1-5-32-545</GroupId>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>true</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
    <DeleteExpiredTaskAfter>PT0S</DeleteExpiredTaskAfter>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>SyncAppvPublishingServer.exe</Command>
      <Arguments>2 -NetworkCostAware -HidePublishingRefreshUI</Arguments>
      <WorkingDirectory>C:\Windows\System32</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

AppV_Repair.xml:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2016-09-18T22:07:37</Date>
    <Author>CHALLAZ</Author>
    <URI>\AppV_Repair</URI>
  </RegistrationInfo>
  <Triggers>
    <RegistrationTrigger>
      <EndBoundary>2020-01-01T00:00:00</EndBoundary>
      <ExecutionTimeLimit>PT30M</ExecutionTimeLimit>
      <Enabled>true</Enabled>
    </RegistrationTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <GroupId>S-1-5-32-545</GroupId>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>true</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
    <DeleteExpiredTaskAfter>PT0S</DeleteExpiredTaskAfter>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>
      <Arguments>-Executionpolicy Bypass -WindowStyle Hidden -NonInteractive -Command "&amp; {Repair-AppvClientPackage * -Extensions}"</Arguments>
      <WorkingDirectory>C:\Windows\System32\WindowsPowerShell\v1.0\</WorkingDirectory>
    </Exec>
  </Actions>
</Task>


No comments:

Post a Comment