OpsaC - Operating as PowerShell code
published: July 23, 2023 author: Tinu tags: PowerShell - PSConfEU categories: DevOps - PowerShell
Die PSConfEU 2023 hatte im schönen Prag in Tschechien stattgefunden. Ich konnte wieder viel von meinen weltweiten Community Members und ihren Tools und Techniken und ihrem Mindset lernen.
Bei Demos mit Visual Studio Code ist es besser auf den light Mode zu wechseln, damit der Code im ganzen Raum besser lesbar wird.
PSReadLine in der Version 2.2.6 bietet eine bessere History und kann auf ListView umgestellt werden.
Set-PSReadLineOption -PredictionViewStyle ListView
PSStyle formatiert die Ausgabe farblich (Kopfzeilen werden grün und Inhalte weiss formatiert).
Jeff Hicks hat eine Session PowerShell with Style bei der PSUG Rhein Neckar darüber gehalten.
Install-Module -Name Microsoft.PowerShell.ConsoleGuiTools
Get-Command -Module Microsoft.PowerShell.ConsoleGuiTools | Select -ExpandProperty Name
Out-ConsoleGridView
Show-ObjectTree
Terminal.Gui.dll und NStack.dll aus dem Nuget Package Terminal.Gui werden benötigt um Terminal GUIs mit mehr Möglichkeiten als die aus den ConsoleGuiTools von Microsoft zu benutzen. Die Assemblies sind unter anderem im Project PSWorkItem von Jeff Hicks abgelegt:
https://github.com/jdhitsolutions/PSWorkItem/tree/main/assemblies
PowerShell, Git, VM Templates mit Packer automatisieren, Terrafrom, Ansible, API benutzen.
Installation Terraform: https://developer.hashicorp.com/terraform/install
Mac via brew:
brew tap hashicorp/tap<br></br>brew install hashicorp/tap/terraform
Windows mit Chocolatey:
choco install -y terraform
Einführung in Terraform siehe https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli
So schnell wie möglich MVP - Minimum Viable Product ausliefern, statt warten bis alles perfekt fertig ist.
SOAP vs. REST API, SOAP ist die alte Schnittstelle basierend auf XML und ist langsam, REST API ist die neuere Schnittstelle und um ein Vielfaches schneller als SOAP.
#Overhead
$oVMHost = Get-VMHost
Show-Object $oVMHost
#Fast
$fVMHost = Get-View -ViewType HostSystem
Show-Object $fVMHost
Show-Object aus dem PSModule PowerShellCookbook von Lee Holmes bietet eine grafische Oberfläche, mit der ein Objekt erkundet und navigiert werden kann.
Cis Service ist ähnlich wie REST API.
$CISServer = 'vcenter.server.local'
$CISCredential = Get-Credential
Connect-CisServer -Server $CISServer -Credential $CISCredential
$tagService = Get-CisService -Name 'com.vmware.cis.tagging.tag'
$vmService = Get-CisService -Name 'com.vmware.vcenter.VM'
Will man ein Terminal als Admin im gleichen Fenster als neuen Tab starten, muss zuerst gsudo installiert werden.
choco install gsudo -y
Danach kann man ein Profile PowerShell (Admin) erstellen und konfigurieren.
Befehlszeile: gsudo pwsh -nologo
Andrew Pruski - dbafromthecold on github.com
write vim + i $psversiontable.psversion
press esc
write :.w !pwsh
### Ausführen von mehreren Zeilen
write vim, i
$modules = Get-ChildItem /opt/microsoft/powershell/7/Modules
foreach($item in $modules){
$item.name
}
<empty line>
press esc, v, 4x Tab
press :
'<,'>
write w !pwsh
### Vim und Terminal gleichzeitig anzeigen
write vim, i + Get-ChildItem /opt/microsoft/powershell/7/Modules
press esc
write :below term
press Ctrl + w
press Arrow up
write :.w !pwsh -nologo
exit
git clone https://github.com/preservim/nerdtree.git ~/.vim/pack/vendor/start/nerdtree
vim -u NONE -c "helptags ~/.vim/pack/vendor/start/nerdtree/doc" -c q
vim
touch ~/.vimrc
"vim generic settings
set number
set nowrap
"set default shell
set shell=pwsh\ -nologo
set filetype=ps1
set ruler
set smartindent "automatically set indents when writing code
set tabstop=4 "set number of spaces a tab is
set shiftwidth=4 "set number of spaces an indent is
set expandtab "tabs become spaces
"remove text from NERDTree UI
let NERDTreeMinimalUI=1
"fix issues with colors in windows terminal
set termguicolors
"syntax highlighting on
syntax on
"highlight line cursor is on
set cursorline
set nocompatible
filetype on
filetype plugin on
filetype indent on
colorscheme blue
"set aliases
cnoreabbrev powershell powershell -executionpolicy unrestricted -nologo
cabbrev bterm below term
cabbrev ntree NERDTree
"open terminal and NERDTree on start up and in new tabs
autocmd VimEnter * :below terminal
autocmd VimEnter * :NERDTree
"shortcut to execute commands in terminal
noremap <C-;> Y<C-W>j<C-W>"0<C-W>k
"shortcut for scrolling in terminal (i to exit)
tnoremap <C-b> <C-\><C-n>
"shortcut for switching between code and terminal
noremap <C-/> <C-w>j
tnoremap <C-/> <C-w>k
"shortcut mapping ctrl+right to open new editor
noremap <C-Right> :vsplit new.ps1<CR>