Skip to content

Instantly share code, notes, and snippets.

View atao's full-sized avatar
🇲🇫

ATAO atao

🇲🇫
  • Share-Link (FR)
View GitHub Profile
@atao
atao / regex.ps1
Created December 18, 2018 14:19
Regex example in PowerShell
$message = '(001945) 12/18/2018 10:50:47 AM - (not logged in) (127.0.0.1)> 530 Login or password incorrect!'
$message -match '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)(.*)(incorrect!)'
$Matches[0]
$Matches[1]
$Matches[2]
$Matches[3]
#Requires -Version 3.0
# Configure a Windows host for remote management with Ansible
# -----------------------------------------------------------
#
# This script checks the current WinRM (PS Remoting) configuration and makes
# the necessary changes to allow Ansible to connect, authenticate and
# execute PowerShell commands.
#
# All events are logged to the Windows EventLog, useful for unattended runs.
@atao
atao / reboot.ps1
Last active April 20, 2018 09:11
Test-PendingReboot
# http://ilovepowershell.com/2015/09/10/how-to-check-if-a-server-needs-a-reboot/
function Test-PendingReboot
{
if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return $true }
if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return $true }
if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true }
try {
$util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
$status = $util.DetermineIfRebootPending()
if(($status -ne $null) -and $status.RebootPending){
@atao
atao / backup-ansible.sh
Created April 10, 2018 10:37
Backup Ansible
#!/bin/bash
###########################################
# Backup Ansible
###########################################
# auteur : atao
VERSION="2018.04.10"
# Source : https://github.com/blogmotion/bm-RaspberryPi/blob/master/Backup%20scripts/backupToNas.sh
# Source : https://tecadmin.net/mysql-database-backup-to-ftp-server-shell-script/
# licence type : Creative Commons Attribution-NoDerivatives 4.0 (International)
# licence info : http://creativecommons.org/licenses/by-nd/4.0/
@atao
atao / create_zip.ps1
Created August 23, 2017 14:10
Create zip from powershell
function copy-ToZip($fileSaveDir){
$srcdir = $fileSaveDir
$zipFile = "$env:localappdata\tmp\Report.zip"
if(-not (test-path($zipFile)))
{set-content $zipFile ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18));(dir $zipFile).IsReadOnly = $false}
$shellApplication = new-object -com shell.application;$zipPackage = $shellApplication.NameSpace($zipFile)
$files = Get-ChildItem -Path $srcdir
foreach($file in $files){$zipPackage.CopyHere($file.FullName);while($zipPackage.Items().Item($file.name) -eq $null){Start-sleep -seconds 1 }}
}
$fileSaveDir = 'C:\Users\USER\AppData\Local\tmp\blabla'
@atao
atao / netsh.bat
Created July 18, 2017 09:42
How manage wireless networks with netsh?
REM Info for an interface
Netsh WLAN show interfaces
Netsh WLAN show interface name="Interface_Name"
REM Export Wireless key
Netsh WLAN export profile key=clear folder="c:\Temp"
REM Import profile
Netsh WLAN add profile filename="File_Path.XML"
@atao
atao / Screenshot.ps1
Created July 18, 2017 09:03
Screenshot function
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
$date = Get-Date -Format yyyyMMddHHmmss
$File = "C:\Temp\Shot-$date.bmp"
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = $Screen.Width
$Height = $Screen.Height
$Left = $Screen.Left
@atao
atao / DL.ps1
Last active July 17, 2017 15:14
Vidéo Download from website using YouTube-dl
# Vidéo Download from website using YouTube-dl
# Version 17/07/2017
$data = Invoke-WebRequest "https://www.tf1.fr/tf1/c-est-canteloup"
# Get links
$data = $data.links | select href
# Remove Warning for exe
$env:SEE_MASK_NOZONECHECKS = 1
foreach ($line in $data){
if ($line.href -like "https://www.tf1.fr/tf1/c-est-canteloup/videos/*")
@atao
atao / encrypt-decrypt.ps1
Created July 11, 2017 11:58
Functions to crypt and decrypt string
# http://community.idera.com/powershell/powertips/b/tips/posts/encrypting-text-information-using-passphrase
function encrypt{
param(
[string]$pass,
[string]$text
)
$key = [Byte[]]($pass.PadRight(24).Substring(0,24).ToCharArray())
# $secure = $text | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString -Key $key
$secure = $text |
ConvertTo-SecureString -AsPlainText -Force |
@atao
atao / Wallpaper.ps1
Created July 7, 2017 12:34
Change wallpaper
# http://www.ghislain-lerda.com/2016/10/07/change-wallpaper/
$wallpaperPath = "mon_image.png"
$setwallpapersource = @"
using System.Runtime.InteropServices;
public class wallpaper
{
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;