Jump to content

Test Powershell

From wikiNonStop
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Function Get-FileName($initialDirectory)
{    
 [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null

 $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
 $OpenFileDialog.initialDirectory = $initialDirectory
 $OpenFileDialog.filter = "All bz2 files (*.bz2)| *.bz2"
 $OpenFileDialog.ShowDialog() | Out-Null
 $OpenFileDialog.filename
} #end function Get-FileName

# *** Script MAIN ***

Write-Host  -BackgroundColor green "rebuilding MLEB bz2 to gz\n"
Write-Host

$Pathscript = $PSScriptRoot
$Pathbz2    = Split-Path -Parent $Pathscript

Write-Host "scriptPath: $Pathscript " 
Write-Host "bz2Path: $Pathbz2 "
Write-Host

$filename = Get-FileName -initialDirectory "$Pathbz2"

if (-not $filename) {
    #Write-Error "Cancel?!"
    Write-Host "no file: canceled  ?"
} else {
    Write-Host "converting $filename to a gz file" 
    #-split "red yellow blue green"
    Write-Host "filename: $filename"
    #$filename.Split("-")[2] -Split(".tar.bz2")
    #$filename.Split("-").Split(".tar.bz2")

    $fdate = $filename.Split("-").Split(".tar.bz2")
    $fdate = $fdate[1] 
    #Write-Host "Date is" $fdate 

    Write-Host "creating temp directory"
    New-Item      -Path $Pathbz2\temp -ItemType directory -Force  
    Remove-Item         $Pathbz2\temp\* -Recurse -Force  
    Set-Location  -Path $Pathbz2\temp
    # ls
    Get-Childitem -Path $Pathbz2\temp
    Write-Host "unpacking $filename" tar -xvf 
    tar -xf  $filename
    Write-Host "packing MLEB-$fdate.tar.gz" 
    tar -czf MLEB-$fdate.tar.gz INSTALL.MediaWikiLanguageExtensionBundle -C extensions *

    Copy-Item "MLEB-$fdate.tar.gz" -Destination "$Pathbz2"

    #transfer file
    
}
#Write-Host "Write-Host"
#Write-Error "Write-Error" -Category PermissionDenied
#Write-Progress  -Activity "Search in Progress" -Status "10% Complete:"
#Write-Progress  -Activity "Search in Progress" -Status "20% Complete:"

Read-Host "hit enter to continue"