powershell 创建PowerShell脚本以完成由SickRage启动的解包过程,但通常会失败 - 这简化了大规模迁移到他们的

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 创建PowerShell脚本以完成由SickRage启动的解包过程,但通常会失败 - 这简化了大规模迁移到他们的相关的知识,希望对你有一定的参考价值。

# VARIABLES
$i = 0
$x = 0
$dirList = Get-ChildItem -Directory
$seasonArr = @{"00" = "Season 00";"01" = "Season 01";"02" = "Season 02";"03" = "Season 03";`
                "04" = "Season 04";"05" = "Season 05";"06" = "Season 06";"07" = "Season 07";`
                "08" = "Season 08";"09" = "Season 09"}

# EXECUTION
foreach ($dir in $dirList) {

    $i = $i + 1
    $properName = $dir.Name
    $readDir = Get-ChildItem -Path $dirName -Recurse

    if ($properName -match "_UNPACK_") {

        $remUnpack = $properName.Substring(8)               # Removing leading _UNPACK_
        $pos = $remUnpack.IndexOf("0")                      # Setting center point (First 0 encountered)
        $showName = $remUnpack.Substring(0, $pos)           # Left part of file name from $pos
        $showName = $remUnpack.Substring(0, $pos-2)         # Trim off white space and S 
        $season = "S0" + $remUnpack.Substring($pos+1, 4)    # Grabbing SxxExx
        Write-Host "$i. $showName - $season"                # Confirming proper values

        foreach ($file in $readDir) {

            $x = $x + 1                                     # Counter
            $seasonPos = $season.IndexOf("E")               # Setting center point (First E encountered)
            $seasonVar = $season.Substring(0, $seasonPos)   # Left part of file name from $seasonPos
            $seasonVar = $seasonVar.TrimStart("S")          # Trimming leading S for just the season number
            $seasonName = $seasonArr.$seasonVar             # Pulling proper season name from hash table made earlier
            $source = "\\freenas\Downloads\Complete\$properName"
            $destination = "\\freenas\TV\$showName\$seasonName"
            $fileName = $file.Name

            try {
                robocopy $source $destination $fileName /MOV    # Requires robocopy - only moves files from source to destination
            } catch {
                Write-Host "[ ERROR ] $showName - $season : Error During Move"
            }

            Write-Host "[ $x / $i ] $showName - $season : Moved Successfully"
        }
    }
}

以上是关于powershell 创建PowerShell脚本以完成由SickRage启动的解包过程,但通常会失败 - 这简化了大规模迁移到他们的的主要内容,如果未能解决你的问题,请参考以下文章

尝试创建删除电子邮件 powershell 脚本

powershell PowerShell脚本,用于创建在计算机启动时运行choco升级的计划任务

在过去 1 分钟创建的文件中查找特定单词的 Powershell 脚本

嵌入 Powershell 脚本问题

在 Bamboo 中从 powershell 脚本创建元数据

PowerShell脚本-如果不存在则创建组