Skip to content

Instantly share code, notes, and snippets.

View it-praktyk's full-sized avatar

Wojciech Sciesinski it-praktyk

View GitHub Profile
# Part of the Vagrant file
# Vagrant plugins triggers and scp are needed
config.trigger.before :destroy,:vm => "<VMNAME>", :force => true, :stdout => false, :stderr => false do
info "Creating backup of files from virtual machines"
run "./backup-before-destroy.sh"
end
# The file backup-before-destroy.sh
#/bin/bash
#!/usr/bin/env python
import sys
import yaml
def main(argv):
with open(argv[0]) as stream:
try:
#print(yaml.load(stream))
@it-praktyk
it-praktyk / gist:90b3ad4d85b5bbac6c973fb3d337779c
Last active October 28, 2016 23:24
Ansible timezone for CentOS
---
tasks:
- name: Check current timezone
shell: timedatectl | grep zone | awk '{ print $3}'
register: current_zone
changed_when: False
notify:
- restart Cron service
- name: Set timezone to {{ timezone }}
#Create new PSDrives
$ProfileDrive = ((Get-Item env:APPDATA).Value).substring(0, 2)
$DesktopPath = $ProfileDrive + (Get-Item env:HOMEPATH).Value + '\Desktop'
$PSDrive1 = @("Desktop:","$DesktopPath")
$ScriptsPath = $ProfileDrive + (Get-Item env:HOMEPATH).Value + '\Documents\Scripts'
$PSDrive2 = @("Scripts:","$ScriptsPath")
$PSDrivesToCreate = @($PSDrive1,$PSDrive2)
Function GenerateScriptDocumentationInMarkdown {
<#
.Synopsis
Generates documentation for a folder-full of scripts using the integrated Get-Help CMDlets.
.Description
Generates a .markdown documentat for each PS1 script in a folder which has the necessary headers required by Get-Help. Also generates an index document which lists (and links to) all generated documentats. Each file name is preceeded with "script_ps1_" so that they are listed together when viewing the Wiki documents.
.Parameter SourceScriptFolder
Source folder where the scripts are located
#Assign default parameters values to some cmdlets - only works with Powershell 3.0 and newer :-/
if (([Version]$psversiontable.psversion).major -ge 3) {
$DefaultParameterVaulesToAdd = @(@('Export-CSV:Delimiter', ';'), @('Export-CSV:Encoding', 'UTF8'), @('Export-CSV:NoTypeInformation', '$true'))
$DefaultParameterVaulesToAddCount = $DefaultParameterVaulesToAdd.Lenght
for ($i = 0; $i -lt $DefaultParameterVaulesToAddCount; $i++) {
$CurrentParameterValue = $DefaultParameterVaulesToAdd[$i][0]
@it-praktyk
it-praktyk / Get-HelpByMarkdown.ps1
Created January 3, 2016 00:31 — forked from urasandesu/Get-HelpByMarkdown.ps1
This script converts PowerShell comment-based help to GitHub Flavored Markdown.
#
# File: Get-HelpByMarkdown.ps1
#
# Author: Akira Sugiura (urasandesu@gmail.com)
#
#
# Copyright (c) 2014 Akira Sugiura
#
# This software is MIT License.
#
@it-praktyk
it-praktyk / gist:e62ed68023f2bf22a407
Created March 7, 2015 22:06
Display all data about the last PowerShell error
$error[0] | fl * -f
For catch is needed exception field value "System.Management.Automation.CommandNotFoundException"
e.g.
PSMessageDetails :
Exception : System.Management.Automation.CommandNotFoundException: The term 'Get-AcceptedDomain' is not recognized as the name of a cmdle
t, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the pat
h is correct and try again.
@it-praktyk
it-praktyk / get-decision.ps1
Created January 18, 2015 01:32
Get the decision from user in PowerShell console
$title = "Delete Files"
$message = "Do you want to delete the remaining files in the folder?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
"Deletes all the files in the folder."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
"Retains all the files in the folder."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)