Задать вопрос
Ответы пользователя по тегу cmd/bat
  • Как последовательно вызвать утилиту с набором аргументов?

    @alhaos
    param(
        $process = "C:\Windows\System32\PING.EXE",
        $argsSetArray = @(
            "127.0.0.1 -n 3",
            "127.0.0.1 -n 5",
            "127.0.0.1 -n 7"
        )
    )
    
    $argsSetArray.ForEach{
        Start-Process $process -ArgumentList $_ -Wait
    }


    без -Wait будет параллельно
    Ответ написан
    Комментировать
  • Перенос файлов в папки год\месяц?

    @alhaos
    param (
        [System.IO.DirectoryInfo]$sourseDirectory = "C:\Program Files\Far Manager",
        [System.IO.DirectoryInfo]$destinationDirectory = "D:\tmp",
        [int]$useCreationOrModifiedFileDateTimeSwitch = 0 # [0] (Use Creation DateTime) or [1] (Use Modified DateTime)
    )
    
    enum CreationOrModifiedFileDateTimeSwitch{
        UseCreationDateTime = 0
        UseModifiedDateTime = 1
    }
    
    class FileCopyer{
        hidden [System.IO.DirectoryInfo]$sourseDirectory
        hidden [System.IO.DirectoryInfo]$destinationDirectory
        hidden [CreationOrModifiedFileDateTimeSwitch]$useCreationOrModifiedFileDateTimeSwitch
    
        FileCopyer([System.IO.DirectoryInfo]$sourseDirectory, [System.IO.DirectoryInfo]$destinationDirectory, [CreationOrModifiedFileDateTimeSwitch]$useCreationOrModifiedFileDateTimeSwitch){
            $this.sourseDirectory = $sourseDirectory
            $this.destinationDirectory = $destinationDirectory
            $this.useCreationOrModifiedFileDateTimeSwitch = $useCreationOrModifiedFileDateTimeSwitch
        }
    
        [void] CopyFiles() {
            Get-ChildItem -Path $this.sourseDirectory -File | ForEach-Object {
                if ($useCreationOrModifiedFileDateTimeSwitch -eq [CreationOrModifiedFileDateTimeSwitch]::UseModifiedDateTime){
                    $year = [int]($_.LastWriteTime.ToString('yyyy'))
                    $month = [int]($_.LastWriteTime.ToString('MM'))
                } else {
                    $year = [int]($_.CreationTime.ToString('yyyy'))
                    $month = [int]($_.CreationTime.ToString('MM'))
                }
                $pathWithYear = Join-Path $this.destinationDirectory -ChildPath $year
                if (!(Test-Path $pathWithYear)) {New-Item $pathWithYear -ItemType Directory}
                $pathWithYearMonth = Join-Path $pathWithYear -ChildPath $month
                if (!(Test-Path $pathWithYearMonth)) {New-Item $pathWithYearMonth -ItemType Directory}
                Copy-Item $_.FullName -Destination $pathWithYearMonth
            }
        }   
    }
    
    $FileMoverInstance = [FileCopyer]::New($sourseDirectory, $destinationDirectory, $useCreationOrModifiedFileDateTimeSwitch)
    $FileMoverInstance.CopyFiles()
    Ответ написан
    Комментировать
  • Скрипт копирования папок?

    @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 комментария
  • Вытянуть строку с PowerShell?

    @alhaos
    ([regex]"(?<=: )([0-9A-F]{2}-){5}[0-9A-F]{2}\s").Matches((&{ipconfig /all})).Value
    Ответ написан
    Комментировать