For copying files from one location to another location using robocopy

Filecopy.vbs


On Error Resume Next
Set oShell=WScript.CreateObject("WScript.Shell")
Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")

oShell.Run("robocopy" & " " & Chr(34) & "%LocalAppdata%\Microsoft\AppV\Client\Integration\PKGID\Root\VFS\ProgramFilesX86\Foldername" &

Chr(34) & " " & Chr(34) & "%LocalAppdata%\Microsoft\AppV\Client\VFS\PKGID\APPV_ROOT\Foldername" & Chr(34) & " " & "/e /R:1 /W:2")

oShell.Run("robocopy" & " " & Chr(34) & "%LocalAppdata%\Microsoft\AppV\Client\Integration\PKGID\Root\VFS\ProgramFilesX86\Foldername

\shortfolder" & Chr(34) & " " & Chr(34) & "%AppData%\shortfolder" & Chr(34) & " " & "/e /R:1 /W:2")

oshell.Run("Powershell.exe -noexit %LocalAppdata%\Microsoft\AppV\Client\Integration\PKGID\Scripts\Shortcut.ps1")



<appv:UserScripts>
  <appv:StartVirtualEnvironment RunInVirtualEnvironment="true">
   <appv:Path>POWERSHELL.EXE</appv:Path>
   <appv:Arguments>-ExecutionPolicy RemoteSigned -File "[{AppVPackageRoot}]\..\Scripts\HKCU.ps1"</appv:Arguments>
   <appv:Wait RollbackOnError="false" />
  </appv:StartVirtualEnvironment>
  <appv:PublishPackage>
   <appv:Path>WSCRIPT.EXE</appv:Path>
   <appv:Arguments>"[{AppVPackageRoot}]\..\Scripts\Filecopy.vbs"</appv:Arguments>
   <appv:Wait RollbackOnError="false" />
  </appv:PublishPackage>
  <appv:UnpublishPackage>
   <appv:Path>POWERSHELL.EXE</appv:Path>
   <appv:Arguments>-ExecutionPolicy RemoteSigned -File "[{AppVPackageRoot}]\..\Scripts\RDDir.ps1"</appv:Arguments>
   <appv:Wait RollbackOnError="false" />
  </appv:UnpublishPackage>
 </appv:UserScripts>


HKCU.ps1

$Server1 = Get-itemproperty "HKCU:\Software\KeyName"
$var1 = $Server1."valuename"
$var1 = $var1.ToLower()

$FINALVALUE = "Final"
$TESTVALUE = "TEST"

$regpath2 = "HKCU:\Software\KeyName1"

if (($var1 -eq "test") -or ($var1 -eq "test1") -or ($var1 -eq "test2") -or ($var1 -eq "test3") -or ($var1 -eq "test4")) {
Set-ItemProperty -path $regpath2 -Name "CurrentEnvironment" -Value "$TESTVALUE" -Force
}
else {
Set-ItemProperty -path $regpath2 -Name "CurrentEnvironment" -Value "$FINALVALUE
}

$HD = $ENV:HDRIVE

if(-not (Test-Path "$HD\Documents\TEstKey")){
            New-Item -Path "$HD\Documents\TEstKey" -ItemType directory -Force
}
if(-not (Test-Path "$HD\TEstKey")){
            New-Item -Path "$HD\TEstKey" -ItemType directory -Force
}
if(-not (Test-Path "$HD\Testkey1")){
            New-Item -Path "$HD\Testkey1" -ItemType directory -Force
}

RDDir.ps1
$scriptpath= $MyInvocation.MyCommand.Path
$dir =Split-path $scriptpath

$Hname= $env:APPDATA
$Reg1 = $Hname+= "\Microsoft\Windows\Start Menu\Programs\shortname.lnk"
Remove-Item -path $Reg1 -Recurse


---------------------------------------


 <appv:UserScripts>
    <appv:StartVirtualEnvironment>
      <appv:Path>WSCRIPT.EXE</appv:Path>
      <appv:Arguments>"[{AppVPackageRoot}]\Addin_Install.vbs"</appv:Arguments>
      <appv:Wait RollbackOnError="false" />
    </appv:StartVirtualEnvironment>
    <appv:UnpublishPackage>
      <appv:Path>POWERSHELL.EXE</appv:Path>
      <appv:Arguments>-ExecutionPolicy RemoteSigned -windowStyle Hidden -File "[{AppVPackageRoot}]\..\Scripts

\DelAddin.ps1"</appv:Arguments>
      <appv:Wait RollbackOnError="false" />
    </appv:UnpublishPackage>

Executable.ps1

$dir = Split-Path $script:MyInvocation.MyCommand.Path

$REG = $dir += "\MainExe.exe"


&$REG

permission.ps1

$curdir = $PSScriptRoot

$parent0 = $curdir

$parent1 = (Get-Item $parent0).Parent.FullName

$root = $parent1 + "\Root\config"

$arg0 = $root + " /grant Users:(OI)(CI)F"

Start ICACLS.EXE -ArgumentList $arg0


----------------------------------------------


    <UserScripts>
      <PublishPackage>
        <Path>POWERSHELL.EXE</Path>
        <Arguments>-ExecutionPolicy RemoteSigned -File "[{AppVPackageRoot}]\..\Scripts\Shortcutcreation.ps1"</Arguments>
        <Wait RollbackOnError="false" />
      </PublishPackage>
      <UnpublishPackage>
        <Path>POWERSHELL.EXE</Path>
        <Arguments>-ExecutionPolicy RemoteSigned -File "[{AppVPackageRoot}]\..\Scripts\Removefolder.ps1"</Arguments>
        <Wait RollbackOnError="false" />
      </UnpublishPackage>
    </UserScripts>
  </UserConfiguration>
  <!-- Machine Wide Configuration -->
  <MachineConfiguration>
    <!-- Product Source URL Section -->
  
    <Subsystems>
      <!-- Machine Wide Virtual Registry Section -->
      <Registry />
    </Subsystems>
    <!-- Machine Scripts Section -->
    <MachineScripts>
      <AddPackage>
        <Path>POWERSHELL.EXE</Path>
        <Arguments>-ExecutionPolicy RemoteSigned -File "[{ProgramFilesX86}]\Mainfolder\makelink.ps1"</Arguments>
        <Wait RollbackOnError="false" />
      </AddPackage>


makelink.ps1 (keep the script from where u want to create as link)
$curdir = $PSScriptRoot
$parent = $curdir
do
{
  $parent = (Get-Item $parent).Parent.FullName
 
}
while (($parent.EndsWith("Root")) -eq $false)


Start-sleep 3

$cmdline = " /C mklink /D " + "$env:ProgramData\DummyFoldername" + ' "' + $curdir + '"'

Start CMD.exe -ArgumentList $cmdline


shortcutcreation.ps1

$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
$arg1 = Split-Path -Path $dir -Parent
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$HName = $env:APPDATA
$HName3 = $env:APPDATA


$REG1 = $HNAME+="\Microsoft\Windows\Start Menu\Programs\Shortcut Main folder name"
$REG4 = $HNAME3+="\Microsoft\Windows\Start Menu\Programs\Shortcut Main folder name\Subfolder"


$arg3 = "$dir\Shortcut name.lnk"
$arg4 = "$dir\2nd shrotcut name.lnk"


# creating shortcut folders


New-Item $REG1 -type directory
New-Item $REG4 -type directory


#Copying Shortcut Files
Copy-Item -Path $arg3 -Destination $REG1 -Recurse -Force
Copy-Item -Path $arg4 -Destination $REG4 -Recurse -Force