• Скрипт копирования папок?

    @alhaos
    <#
    .SYNOPSIS
        a script that creates a folder and copies another folder into it depending on the user's choice
    .PARAMETER clearCorpDatabaseDirecoryName
        directory name which contains clear Corporate database.
    .PARAMETER clearProfDatabaseDirecoryName
        directory name which contains clear Professional database.
    .PARAMETER clearBasicDatabaseDirecoryName
        directory name which contains clear Basic database.
    .PARAMETER databaseDirecoryName
        Specifies the directory where will be created new directory.
    #>
    
    param (
        [System.IO.DirectoryInfo]$clearCorpDatabaseDirecoryName = "d:\чистые базы\корп",
        [System.IO.DirectoryInfo]$clearProfDatabaseDirecoryName = "d:\чистые базы\проф",
        [System.IO.DirectoryInfo]$clearBasicDatabaseDirecoryName = "d:\чистые базы\базовая",
        [System.IO.DirectoryInfo]$databaseDirecoryName = "D:\tmp"
    )
    
    enum DatabaseEdition {
        corp = 0
        prof = 1
        basic = 2
    }
    
    try {
        [String]$companyName = Read-Host -Prompt "Enter company name"
        [DatabaseEdition]$userChoice = Read-Host -Prompt "Select database type 0 - corp, 1 - prof or 2 - basic"
    
        $companyDirectory = New-Item -ItemType Directory -Path (Join-Path $databaseDirecoryName -ChildPath $companyName)
        switch ($userChoice){
            corp {
                Write-Host "User choice corporate"
                Copy-Item $clearCorpDatabaseDirecoryName -Destination $companyDirectory.FullName -Recurse
                "Directory {0} directory copied to {1}" -f $clearCorpDatabaseDirecoryName, $companyDirectory.FullName
    
            }
            prof {
                Write-Host "User choice professional"
                Copy-Item $clearProfDatabaseDirecoryName -Destination $companyDirectory.FullName -Recurse
                "Directory {0} directory copied to {1}" -f $clearCorpDatabaseDirecoryName, $companyDirectory.FullName
            }
            basic {
                Write-Host "User choice basic"
                Copy-Item $clearBasicDatabaseDirecoryName -Destination $companyDirectory.FullName -Recurse
                "Directory {0} directory copied to {1}" -f $clearCorpDatabaseDirecoryName, $companyDirectory.FullName
            }
        }
    }
    catch {
        Write-Host "An error occurred:"
        Write-Host $_
    }
    Ответ написан
    3 комментария