Advertisement
DanielDanielDaniel

Get-Plantilla

May 11th, 2025
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.92 KB | Source Code | 0 0
  1. # Funciona para PowerShell Versiones >=5.2
  2. function Get-Plantilla{
  3.     ## Descarga una plantilla de pasterbin.com
  4.     ## @Param type : Tipo de plantilla (html, c, c++, servidor simple python)
  5.     ## @Param name_file : Nombre con el que se guardara el archivo.
  6.     ## @Return name_file
  7.     # @TODO: Hacer el equivalente en python.
  8.     param(
  9.         [String]$type,
  10.         [String]$name_file
  11.     );
  12.     $recomende_lang="html, c, c++";
  13.     $pls="server";
  14.     if ($type -eq ""){
  15.         Write-Error -Message "Error no se paso el tipo de plantilla." -ErrorId "-1" -RecommendedAction ("Se recomienda inglesar estos lenguajes: "+$recomende_lang+" o estas plantillas "+$pls)
  16.         return -1;
  17.     }
  18.     $name_output=if ($name_file -eq ""){"main.$type"}else{$name_file};
  19.     $url_from_plantilla="https://pastebin.com/raw/igR2QKnH";
  20.     switch($type){
  21.         "html"{
  22.             $url_from_plantilla="https://pastebin.com/raw/igR2QKnH";
  23.             $name_output=if ($name_file -eq ""){"html.$type"}else{$name_file};
  24.         }
  25.         "c"{
  26.             $url_from_plantilla="https://pastebin.com/raw/1U5xQByG";
  27.         }
  28.         "c++"{
  29.             $url_from_plantilla="https://pastebin.com/raw/04Rwptuc";
  30.             $name_output=if ($name_file -eq ""){"main.cpp"}else{$name_file}
  31.         }
  32.         "server"{
  33.             $url_from_plantilla="https://pastebin.com/raw/PUt1pUW3";
  34.             $name_output=if ($name_file -eq ""){"sserver.py"}else{$name_file}
  35.         }default{
  36.             Write-Error -Message "Error no se reconose el lenguaje deseado" -ErrorId "-2" -RecommendedAction ("solo se reconocen los siguientes lenguajes: "+$recomende_lang)
  37.             return -2;
  38.         }
  39.     }
  40.     echo "Descargando plantilla de $url_from_plantilla ..."
  41.     Invoke-WebRequest $url_from_plantilla -OutFile $name_output
  42.     echo "La descarga de la plantilla $type fue un exito:)"
  43.     echo "El nombre del archivo es:"
  44.     return $name_output
  45. }r
Tags: powershell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement