[英]Powershell copy folder and content to destination
I am trying to write a Powershell script that transfers my SID-1 folder to the C:\\temp and then install the .exe files for each program.我正在尝试编写一个 Powershell 脚本,将我的 SID-1 文件夹传输到 C:\\temp,然后为每个程序安装 .exe 文件。 At the moment my efforts merely make C:\\temp\\SID-1\\ but no subfolder or content transfers.
目前我的努力只是使 C:\\temp\\SID-1\\ 但没有子文件夹或内容传输。 Very new to Powershell so feel I am missing something obvious.
Powershell 非常新,所以觉得我错过了一些明显的东西。 I run these as a preloaded script in the Atera MSP.
我将这些作为 Atera MSP 中的预加载脚本运行。
I believe the issue is with the #Transporter section, as it is not copying the whole folder and its content.我相信问题出在 #Transporter 部分,因为它没有复制整个文件夹及其内容。 I have recently attempted to add the IF statement to create C:\\temp
我最近尝试添加 IF 语句来创建 C:\\temp
# Transporter
$Source = '\\server\Deployment\Standard Installs\SID-1\'
$Destination = 'C:\temp\'
Get-ChildItem $Destination | ForEach-Object {Copy-Item -Path $Source -Destination $_ -Recurse -Force}
If(!(test-path $Destination))
{
New-Item -Path $Destination -ItemType directory
}
Everything else below this point is merely an installer for the programs I consider standard installs.低于这一点的其他所有内容都只是我认为标准安装的程序的安装程序。
Below is the full script下面是完整的脚本
# Transporter
$Source = '\\server\Deployment\Standard Installs\SID-1\'
$Destination = 'C:\temp\'
Get-ChildItem $Destination | ForEach-Object {Copy-Item -Path $Source -Destination $_ -Recurse -Force}
If(!(test-path $Destination))
{
New-Item -Path $Destination -ItemType directory
}
$CurrentLocation = 'C:\temp\'
# Installer
#EXE Preloader
$exe = @(
# Internet Browsers
'C:\temp\SID-1\Internet Browser\ChromeSetup.exe',
'C:\temp\SID-1\Internet Browser\Firefox Installer.exe',
'C:\temp\SID-1\Internet Browser\OperaSetup.exe',
# Office 365
'c:\temp\SID-1\Office 365\Setup.X64.en-us_O365BusinessRetail.exe',
'c:\temp\SID-1\Office 365\setuponenotefreeretail.x64.en-us_.exe',
'c:\temp\SID-1\Office 365\Teams_windows.exe',
'c:\temp\SID-1\Office 365\Yammer-ia32-3.4.5.exe',
# Printers
'c:\temp\SID-1\Papercut\client-local-install.exe',
# Utilities
'c:\temp\SID-1\Utilities\7z1805-x64.exe',
'c:\temp\SID-1\Utilities\GrammarlySetup.exe',
'c:\temp\SID-1\Utilities\pwsafe64-3.51.0.exe',
'c:\temp\SID-1\Utilities\readerdc_uk_xa_cra_install.exe',
'c:\temp\SID-1\Utilities\TeamViewer_Host_Setup.exe',
'c:\temp\SID-1\Utilities\AnyDesk.exe'
)
#MSI Preloader
$msi = @(
# AntiVirus
'c:\temp\SID-1\Eset\eset_endpoint_av64.msi'
)
# foreach ($exefile in $exe)
# Internet Browsers
#Google Chrome
Start-Process -FilePath "c:\temp\SID-1\Internet Browser\ChromeSetup.exe" -ArgumentList "/qn" -Wait
#Opera
Start-Process -FilePath "c:\temp\SID-1\Internet Browser\Firefox Installer.exe" -ArgumentList "/qn" -Wait
#Mozilla Firefox
Start-Process -FilePath "c:\temp\SID-1\Internet Browser\OperaSetup.exe" -ArgumentList "/qn" -Wait
# Office 365
#Office 2016 Business Premium 64
Start-Process -FilePath "c:\temp\SID-1\Office 365\Setup.X64.en-us_O365BusinessRetail.exe" -ArgumentList "/qn" -Wait
#Onenote 2016
Start-Process -FilePath "c:\temp\SID-1\Office 365\setuponenotefreeretail.x64.en-us_.exe" -ArgumentList "/qn" -Wait
#Teams 64
Start-Process -FilePath "c:\temp\SID-1\Office 365\Teams_windows.exe" -ArgumentList "/qn" -Wait
#Yammer 64
Start-Process -FilePath "c:\temp\SID-1\Office 365\Yammer-ia32-3.4.5.exe" -ArgumentList "/qn" -Wait
# AntiVirus
#ESET
Start-Process -FilePath "c:\temp\SID-1\Eset\eset_endpoint_av64.msi" -ArgumentList "/qn" -Wait
# Printers
#Papercut
Start-Process -FilePath "c:\temp\SID-1\Papercut\client-local-install.exe" -ArgumentList "/qn" -Wait
# Utilities
#PassVault
Start-Process -FilePath "c:\temp\SID-1\Utilities\pwsafe64-3.51.0.exe" -ArgumentList "/qn" -Wait
#Grammarly
Start-Process -FilePath "c:\temp\SID-1\Utilities\GrammarlySetup.exe" -ArgumentList "/qn" -Wait
#7zip
Start-Process -FilePath "c:\temp\SID-1\Utilities\7z1805-x64.exe" -ArgumentList "/qn" -Wait
#Adobe DC Reader
Start-Process -FilePath "c:\temp\SID-1\Utilities\readerdc_uk_xa_cra_install.exe" -ArgumentList "/qn" -Wait
#TeamViewer
Start-Process -FilePath "c:\temp\SID-1\Utilities\TeamViewer_Host_Setup.exe" -ArgumentList "/qn" -Wait
#Anydesk
Start-Process -FilePath "c:\temp\SID-1\Utilities\AnyDesk.exe" -ArgumentList "/qn" -Wait
You are copying from the destination!您正在从目的地复制! But there probably won't be any files.
但可能不会有任何文件。 You want to do it the other way around.
你想反过来做。 Also you need to copy after the directory was created:
您还需要在创建目录后复制:
# Transporter
$Source = '\\server\Deployment\Standard Installs\SID-1\'
$Destination = 'C:\temp\'
If(!(test-path $Destination))
{
New-Item -Path $Destination -ItemType directory
}
Get-ChildItem $source| ForEach-Object {Copy-Item -Path $_.FullName -Destination $destination -Recurse -Force}
Edit: The even better option is to copy the whole directory.编辑:更好的选择是复制整个目录。 You don't even have to check if the folder already exists, because the script automaticly creates the C:\\temp folder if it isn't there:
您甚至不必检查文件夹是否已经存在,因为如果 C:\\temp 文件夹不存在,脚本会自动创建:
$Source = '\\server\Deployment\Standard Installs\SID-1\'
$Destination = 'C:\temp\'
Copy-Item -Path $source -Destination $destination -Recurse -Force
Please test it, let me know if it worked and if it did, mark my post as the answer :)请测试它,让我知道它是否有效,如果有效,请将我的帖子标记为答案:)
Check if filepath is exist recomend do at start, like this, for me this work good.检查文件路径是否存在推荐在开始时做,像这样,对我来说这项工作很好。
$Source = '\\server\Deployment\Standard Installs\SID-1\'
$Destination = 'C:\temp\'
If(!(test-path $Destination))
{
New-Item -Path $Destination -ItemType directory
}
Copy-Item -Path $Source -Destination $Destination -Recurse -Force
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.