我已经修改了一些脚本,但我无法让这个脚本正常工作。
使用应用程序部署软件,我可以在部署后运行自定义脚本。
此应用程序在启动脚本和一堆文件之前将其复制到某个位置。 文件夹路径可能是随机的,所以我想使用脚本位置。
我想将文件 2 复制到用户 %LOCALAPPDATA% 路径。 Users AppData 文件夹中尚不存在该目录结构。 我需要在复制期间或之前创建文件夹结构。
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
非常感谢。
这应该可以帮你完成。
$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