0
votes

I have butchered a few scripts and I am having trouble getting this one to work.

Using an application to deploy software, I can run a custom script post-deployment.

This application is copying the script and a bunch of files to a location before launching them. The folder path could be random so I want to use the script location.

  • \Path
    • Script
    • File 1
    • File 2

I want to copy File 2 to the Users %LOCALAPPDATA% paths. The directory structure does not exist yet in the Users AppData folder. I need to create the folder structure during or before the copy.

C:\users*\AppData\Local\NewApplication\Folder\

#Declare location of the XML file using spli-path. Copy XML file to all user %LOCALAPPDATA% paths and create folder structure
$scriptPath = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$Source = Join-Path $scriptPath 'Script.ps1'
$Destination = 'C:\users\*\AppData\Local\NewApplication\Folder\'
Get-ChildItem $Destination | ForEach-Object {Copy-Item -Path $Source -Destination $_ -Force -Recurse}
Exit $LASTEXITCODE

Thank you so much.

1

1 Answers

0
votes

This should get it done for you.

$scriptPath = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent 
$Source = Join-Path $scriptPath 'File2.xml' 
$Destination = "$env:LOCALAPPDATA\New Application\Folder" 
if (!([system.io.directory]::Exists($Destination))){ 
    [system.io.directory]::CreateDirectory($Destination) 
} 
# This will only copy the XML file
Get-ChildItem $scriptPath | ForEach-Object {Copy-Item -Path $Source -Destination $Destination -Force -Recurse} 
# This will copy everything in the same directory as the script
#Get-ChildItem $scriptPath | ForEach-Object {Copy-Item -Path $_.Fullname -Destination $Destination -Force -Recurse} 
#Exit $LASTEXITCODE