Posts

PowerShell - Pass Dynamic Arguments from Function to Function

If you are interested in passing dynamic arguments from function to function in PowerShell, I think the following will help you out: Create the function(s) like this function MyFunction1 { [CmdletBinding()] param ( [string]$requiredParm1, [string]$requiredParm2, [parameter(ValueFromRemainingArguments=$True)] $dynamicArgs ) $props = @() if($dynamicArgs) { $num = 0 for ($num = 0; $num -lt $dynamicArgs.Count; $num = $num + 2) { $format_string = (([string]$dynamicArgs[$num]) + " '" + [string]$dynamicArgs[$num+1] + "' ``") $props += $format_string } } $string_props = $($props | Out-String) $second_function = "MyFunction2 -requiredParm1 $requiredParm1 " $second_function += "-requiredParm2 $requiredParm2 " $second_function += "$string_props;" Invoke-Expression $second_function } function MyFunction2 { [CmdletBinding()] param ( [st

Ansible Module - VMWare Update Guest PCI Device

Ansible Module to enable PCI Passthrough for a VM after the Host Device is configured for Passthrough . #!/usr/bin/env python ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community' } DOCUMENTATION = ''' --- module: vmware_update_guest_pci_device short_description: Module to update PCI Passthrough device for a guest version_added: "2.4" description: - "Module to update PCI Passthrough device for a guest, based on device_name or device_id" options: hostname: description: - vSphere service to connect to required: true username: description: - username to connect to vSphere hostname required: true password: description: - username password required: true esxi_hostname: desciption: - Esxi host to make changes to device_name:

Ansible Module - VMWare Update Host PCI Passthrough

Ansible Module to enable PCI Passthrough for a Device on VMWare Host. #!/usr/bin/env python ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community' } DOCUMENTATION = ''' --- module: vmware_update_host_pci_passthrough short_description: Module to update PCI Passthrough device for a host version_added: \"2.4\" description: - \"Module to update PCI Passthrough device for a host, based on device_name or device_id\" options: hostname: description: - vSphere service to connect to required: true username: description: - username to connect to vSphere hostname required: true password: description: - username password required: true esxi_hostname: description: - Esxi host to make changes to device_name: description:

Azure DevOps - Auto Approve PR with PAT

I hear a lot of people ask, how can I problematically approve a PR when using Azure DevOps? See the example script below. You will need a valid PAT, Azure DevOps Org URL, Azure DevOps Project Name/ID. You will have to make small adjustment to the code to work, so please see comments inline. import argparse import json import requests # Go ahead and add all the users you want to approve with a PAT # This is the easiest way, otherwise we would have to run a lot of # api requests to figure out the user identity based on the current # PAT used TEAM = [ 'user1@example.com', 'user2@example.com', ] def submit_to_api(pat=None, url=None, data=None, method="get", return_type='json', json=None): result = None if method == 'get': query_parameters = data headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} if query_parameters: result = requests.get

Ubuntu 18.04 - Ansible Vagrant File for libvert

Ubuntu 18.04 - Ansible Vagrant File See how to install Vagrant libvert here Vagrant File Vagrant.configure("2") do |config| ansible_root = ENV['ANSIBLE_ROOT'] ansible_roles = File.expand_path("roles", ansible_root) ansible_conf_file = File.expand_path("ansible.cfg", ansible_root) ENV['ANSIBLE_ROLES_PATH'] = "#{ansible_roles}" config.vm.box = "generic/ubuntu1804" config.vm.provision "ansible" do |ansible| if ENV['PLAYBOOK_PATH'] ansible.playbook = ENV['PLAYBOOK_PATH'] end ansible.verbose = true ansible.config_file = ansible_conf_file if ENV['INVENTORY_PATH'] ansible.inventory_path = ENV['INVENTORY_PATH'] end if ENV['LIMIT'] ansible.limit = ENV['LIMIT'] end end end Set Ansible Root export ANSIBLE_ROOT=~/{..Your Project Location..}/ansible/ Set Environment Variable export PLAYBOOK_PATH=~/{..You

Ubuntu 18.04 - Install Android Emulator

Android Emulator on Linux Download https://developer.android.com/studio/index.html?hl=sk Extract sudo mkdir /opt/android-studio sudo tar xvzf ~/Downloads/android-studio-ide-192.6308749-linux.tar.gz -C /opt/ Install requirments for 64-bit machine sudo apt update && sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 Optional KVM Install sudo apt install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils sudo adduser `id -un` libvirtd sudo adduser `id -un` kvm sudo reboot #./emulator64-x86 -avd < your AVD name> -qemu -m 2047 -enable-kvm Configure Android Studio cd /opt/android-studio/bin/ ./studio.sh Create desktop/App shortcuts echo '#!/usr/bin/env xdg-open' > ~/Desktop/AndroidStudio.desktop echo '[Desktop Entry]' >> ~/Desktop/AndroidStudio.desktop echo 'Version=1.0' >> ~/Desktop/AndroidStudio.desktop echo 'Type=Application' >> ~/Desktop/AndroidStudio.desktop echo '

Ubuntu 18.04 - Run Android Apps

Ubuntu 18.04 - Run Android Apps Install prerequisites sudo add-apt-repository ppa:morphis/anbox-support sudo apt update sudo apt install anbox-modules-dkms Method 2 - Disable Secure Boot in shim-signed sudo mokutil --disable-validation sudo reboot # Change Secure Boot state # Enter password you created # Select Yes to disable Secure Boot in shim-signed # Press Enter key to finish the whole procedure. (I had to enter the character based on the character location that was requested) # Reboot - to start OS Load kernel models once, reboot will make it stick sudo modprobe ashmem_linux sudo modprobe binder_linux Install anbox snap install --devmode --beta anbox Start anbox on command line or via UI anbox session-manager Enable Unknown Sources under Settings Use https://chrome.google.com/webstore/detail/apk-downloader-for-google/idkigghdjmipnppaeahkpcoaiphjdccm?hl=en extension to download APK from https://play.google.com/store/apps Add APK to anbox adb devices adb install <&

Ubuntu 18.04 - Vagrant Install using libvert Plugin

Ubuntu 18.04 - Vagrant Install using libvert Plugin Dependencies sudo apt install build-essential vagrant ruby-libvirt sudo apt install qemu libvirt-bin ebtables dnsmasq-base sudo apt install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev Install plugin vagrant plugin install vagrant-libvirt Download vagrant box vagrant box add generic/ubuntu1804 --provider=libvirt Download vagrant file vagrant init generic/ubuntu1804 Start Vagrant vagrant up # if you have multiple providers vagrant up --provider=libvirt Destroy VM vagrant destroy Note: You might consider changing directories. You can only have one Vagrant file in a directory and you might want to organize a bit. Refrences https://github.com/vagrant-libvirt/vagrant-libvirt https://computingforgeeks.com/using-vagrant-with-libvirt-on-linux/

Run VM Technology Inside Another VM with Hyper-V

Run VM Technology Inside Another VM with Hyper-V If you are like me, you want to run proof-of-concepts inside a VM. Well this sounds easy enough, but if you dig deep it is pretty challenging to accomplish, when you are testing a VM technology like localstack . The main reason is the VM doesn't have direct access to the processor. Luckily Microsoft has a one line solution to the problem. Just run the following from the host for the VM you want to expose virtualization on. Set-VMProcessor -VMName "VM Name in Hyper-V" -ExposeVirtualizationExtensions $true If you are running KVM, it's possible to do this, but with a bit of extra work. See article  by Fedora. If you are using VirtualBox, don't waste your time as it won't work. It's really too bad that it isn't supported as of yet. Just to note, I haven't gone over enabling virtualization in the bios. You might get an error related that and it should be easy enough to resolve with a web search.

Useful Git Commands

Image
Useful Git Commands I figured the best way to start is to get (git) us on the same page (pun intended) Before I start showing you code for automation, I figure I should show you the very basics that you need to know about using Git . I hope you don't mind, as I won't be wasting valuable screen space on how to install Git. If you run into trouble installing Git, don't worry, you are also going to run into trouble with automation😃 Rest assured, as we all struggle at some point with automation, but finding a solution will bring you pride and joy in your accomplishments. To be successful with automation, you will have to continue to learn new technologies and tools. All joking aside, you will actually find many good resources online and offline that will help you get unstuck. I want to make it very clear that running any of these commands without the knowledge of what they do can be very dangerous. As such, following license applies: This work is licensed under a Creat

Code Syntax Highlighting

Image
Code Syntax Highlighting If you have a site which has code snippets, you probably want to implement code syntax highlighting. How do you implement syntax highlighting? You can easily implement a solution in a few minutes using hightlight.js . Within your HTML page(s) head tag, you will need to add the below three lines of code. The three lines of code import the required css, import the required JavaScript functions and initializes the JavaScript object. <!-- Syntax Highlighting --> <link href='//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/default.min.css' rel='stylesheet'/> <script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js'/> <script>hljs.initHighlightingOnLoad();</script> If you are using a tool like Blogger or WordPress you will need to add the three lines of code to your template. In Blogger it should look something like this: After you implement the previous three lines

PowerShell Unzip File

PowerShell Unzip File OK, I seem to run into this every now and then, so I decided to write it down so I don't forget it. If you need to extract a zip file in PowerShell use the following: Expand-Archive -Path "nugetPackage.zip" "z:\Temp\nugetPackage" You can make this a function, but that seems a little redundant, since it's already a function: function UnzipFile {     param([string] $source, [string] $destination)     Expand-Archive -Path "$source" "$destination" } And you can call the new function like this: UnzipFile "nugetPackage.zip" "z:\Temp\nugetPackage" You might get unsupported archive file type, so you can always rename the file to .zip to get around this; assuming the file is in zip format, but has a different file extension. This happens with .xap, .jar, .nupkg, etc... mv nugetPackage.nupkg nugetPackage.zip Expand-Archive -Path "nugetPackage.zip" "z:\Temp\nugetPackage&

The Goal

The Goal I wanted to start a blog to discuss tools, processes and techniques for automation. I hope that all my topics will work together to help you build an automated system. What is automation? According to dictionary.com automation is: the technique, method, or system of operating or controlling a process by highly automatic means, as by electronic devices, reducing human intervention to a minimum. What does this mean to me? To me, automation is anything that allows us to do something faster in a more automated fashion. In my definition, automation is anything that helps us accomplish less input, provides more consistency and produces more reliability. Automation should have freed us from a portion or all of a task, so we can concentrate our efforts elsewhere. I like a more vague definition: as we can start out by creating easy scripts, that can eventually lead to a textbook version of automation. It is also common to use over engineered programs, when simple process