Skip to content

Instantly share code, notes, and snippets.

@HiroNakamura
Last active December 22, 2023 20:05
Show Gist options
  • Save HiroNakamura/6be42eb8deaa4d96c508a273099f00b7 to your computer and use it in GitHub Desktop.
Save HiroNakamura/6be42eb8deaa4d96c508a273099f00b7 to your computer and use it in GitHub Desktop.
Powershell
Commands Powershell
-- Get Version
Get-Host | Select-Object version
# Change execution policy
Set-ExecutionPolicy RemoteSigned
Copy-Item -Path "C:\Source\Powershell" -Destination "C:\Testumgebung"
Copy-Item -Path "C:\Source\Powershell" -Destination "C:\Testumgebung" -Recurse
Get-Item -Path "C:\"
Get-Item -Path "C:\*"
Get-ChildItem -Path "C:\"
Remove-Item -Path "C:\Source\Test1\*.txt" -Recurse -Force
Copy-Item -Path "C:\Source\*.txt" -Destination "C:\Source\Textfiles" -Recurse
Start-Process powershell.exe
Get-Process
Get-Process powershell
Get-Process powershell,explorer
Get-Process power*
Get-Process powershell | Select-Object name,productversion,company
Get-Process | Get-Member
Stop-Process 23498
Stop-Process -processname notepad
Get-Command ping
Get-Date | Get-Member
Get-Error | Get-Member
# Commands
Get-Help
Get-Help Get-Process
Get-Process | Get-Member
Get-Service
Get-Service | Get-Member
Get-Service | Get-Member -Force
(Get-Service Schedule).PSBase
# Creación de clase
class Modelo{
[string]$Nombre;
[int]$Valor;
[datetime]$FechaCreacion;
[string] ToString(){
return ("Datos = {0}, {1}, {2}"-f $this.Nombre, $this.Valor, $this.FechaCreacion)
}
}
# Herencia
class ModeloCuadrado : Modelo{}
# Instanciación
$myModelo = [Modelo]::new();
$myModelo | Get-Member
$myModeloCuadrado = [ModeloCuadrado]::new();
# Asignación
$myModelo.FechaCreacion = Get-Date
$myModelo.Nombre = "Programando con Powershell"
$myModelo.Valor = 120
$myModeloCuadrado.FechaCreacion = Get-Date
$myModeloCuadrado.Nombre = $myModelo.Nombre
$myModeloCuadrado.Valor = $myModelo.Valor
if($myModelo -ne $null){
Write-Host "Fecha: "$myModelo.FechaCreacion
Write-Host "Nombre: "$myModelo.Nombre
Write-Host "Valor: "$myModelo.Valor
Write-Host $myModelo.ToString()
}
Write-Host "Verdadero? "$myModeloCuadrado -is [ModeloCuadrado]
# Ventana en Powrshell
# Add-Type -AssemblyName 'System.Windows.Forms'
# Add-Type -AssemblyName 'Microsoft.VisualBasic'
# [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
# Init PowerShell Gui
Add-Type -AssemblyName System.Windows.Forms
# Create a new form
$LocalPrinterForm = New-Object system.Windows.Forms.Form
# Define the size, title and background color
$LocalPrinterForm.ClientSize = '500,300'
$LocalPrinterForm.text = "LazyAdmin - PowerShell GUI Example"
$LocalPrinterForm.BackColor = "#ffffff"
# Display the form
[void]$LocalPrinterForm.ShowDialog()
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
$form = New-Object System.Windows.Forms.Form
$form.Text = "Some form"
$form.Size = New-Object System.Drawing.Size(150, 145)
$form.AutoSize = $true
$lbl1 = New-Object System.Windows.Forms.Label
$lbl1.Text = "Hello World!"
$lbl1.Location = New-Object System.Drawing.Point(30, 20);
$lbl1.Add_Click({
[System.Windows.Forms.MessageBox]::Show("Hey!")
})
$btn = New-Object System.Windows.Forms.Button
$btn.Text = "Close"
$btn.location = New-Object System.Drawing.Point(30, 60);
$btn.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $btn
$form.controls.Add($lbl1)
$form.controls.Add($btn)
$Null = $form.ShowDialog()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment