powershell - Powershell 路径名变量
问题描述
在完成了一些在线课程之后,我对 Powershell 脚本非常陌生,并且我已经设置了一项任务来清除模板备份文件夹,并将现有模板移动到备份文件夹中。
我创建的脚本本身没有问题(我希望如此),但是,我们希望这个脚本适用于我们的 PROD 和 DEVTEST 环境——文件路径会有所不同。
如何为 systemfiles 文件夹的文件路径创建变量?
我可以有两个单独的变量,但希望将它作为一个变量。
任何帮助,将不胜感激。谢谢
$ErrorActionPreference = "Stop"
. "$PSScriptRoot\functions.ps1"
$consul_address = $env:bamboo_consul_address
$our_environment = $env:bamboo_our_environment
$location = $env:bamboo_location
$systemfilespath =
"\\oursite.com\shares\APPSystemFiles\${our_environment}" # DEVTEST env locations
"\\oursite\applications\APPLICATIONNAME\Systemfiles\${our_environment}" # PROD env locations
{
Write-Host "Clearing the content on Printing Template Backups from ${our_environment}"
Remove-Item "${systemfilespath}\PrintingRoot\PrintingTemplateBackup/*"
(Move-Item -Path "${systemfilespath}\PrintingRoot\PrintingTemplate/*")
| ForEach-Object
Write-Host "Backing up Printing Template Backup file with Printing Template
file from ${our_environment}"
| Set-Content -Path
"${systemfilespath}\PrintingRoot\PrintingTemplateBackup/*"
}
解决方案
如果您需要从中选择一定数量的选项,并且脚本将被手动触发以启动,您可以提示您想要影响的位置。
$systemfilespath = Read-Host -Prompt "Choose a Location"
Switch ($systemfilespath){
1 {CLS ; Write-Host -ForegroundColor Green "\\oursite.com\shares\APPSystemFiles\${our_environment}"} # or a desc
2 {CLS ; Write-Host -ForegroundColor Green "\\oursite\applications\APPLICATIONNAME\Systemfiles\${our_environment}"} # or a desc
}
推荐阅读
- python - 将热图添加到 curdoc()
- micropython - 按钮不断变高而不按下它
- python - 缩减时间:分钟:秒
- prolog - Prolog 中的构造 s() 代表什么?
- node.js - 部署到heroku时如何解决Node和reactapp错误?
- c# - 方法重载解析的编译器步骤
- python - Python:将每行的所有单元格合并到一个单元格中
- php - file_get_contents(id_rsa):打开流失败:ssh 配置中没有这样的文件或目录
- r - 下载 plotly 瀑布图作为 pdf 在闪亮仪表板中不起作用
- github - 如何将 GitHub 存储库与托管网站同步