-
Ratings(0)
programming
Category
1
Conversations
Capabilities
Browser
Online Search and Web Reading Data Analysis
Visual data analysis Dall·e
Image GenerationDescription
专注于PowerShell编程与代码重构的AI助手,负责审查和改进PowerShell脚本。通过重构提升脚本的可读性、可测试性、可扩展性和可维护性
Prompts
- ```powershell #备份文件夹中的所有文件及指定文件夹到指定目录或者到指定服务器中的指定目录 function BackupOneItem { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string] $Project, #升级项目 [Parameter(Mandatory = $true)] [string] $UpgradePath, #升级文件所在目录 [Parameter(Mandatory = $true)] [string] $BackupPath, #备份文件所在目录 [Parameter(Mandatory = $true)] [string] $SourcePath, #文件所在目录 $ToSession #远程连接Session ) if($null -eq $toSession ) { #如果源文件夹且备份文件夹不存在,创建文件夹 if ((Test-Path -path $SourcePath) -and !(Test-Path -path $BackupPath)) { New-Item $BackupPath -Type Directory if (!(Test-Path -path $BackupPath)) { Write-Log -Level 'ERROR' -Message "备份目录不存在:$backupPath" -Project $Project return } } } else { #远程判断目录是否存在,如果不存在则创建 RemoteTestDirPath $Project $BackupPath $SourcePath $ToSession } foreach($itemInfo in (Get-ChildItem -Path $UpgradePath)) { #如果存在该文件或者文件夹则备份该文件或者文件夹 $tmpSourcePath=$itemInfo.FullName.Replace($UpgradePath,$SourcePath) #如果是文件夹 if ($itemInfo -is [System.IO.DirectoryInfo]) { $newBackupPath = [System.IO.Path]::Combine($BackupPath, $itemInfo.Name) $newSourcePath = [System.IO.Path]::Combine($SourcePath, $itemInfo.Name) #递归 BackupOneItem $Project $itemInfo.FullName $newBackupPath $newSourcePath $ToSession Write-Log -Level 'DEBUG' -Message "Backup directory from `"$($itemInfo.FullName)`" to `"$newDesFolder`" successfully." -Project $Project } else { if($null -eq $ToSession) { if((Test-Path -path $tmpSourcePath)) { Copy-Item -Path $tmpSourcePath -Destination $BackupPath -Force } } else { RemoteCopyOneItem $Project $tmpSourcePath $BackupPath $ToSession } Write-Log -Level 'DEBUG' -Message "Backup file from `"$($itemInfo.FullName)`" to `"$newDesFolder`" successfully." -Project $Project } } } ```
More GPTs by Deloris Huels
More programming GPTs
2.425.0K
2.425.0K
2.325.0K
2.625.0K
2.425.0K
2.625.0K
2.410.0K
2.210.0K
2.510.0K