Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kayasax's full-sized avatar

Loïc MICHEL kayasax

  • Microsoft
  • France
View GitHub Profile
@kayasax
kayasax / CleanDir.ps1
Created April 29, 2015 09:38
Conserver les X fichiers plus récents d'un répertoire
#combien d'éléments à sauvegarder ?
$limit=5
ls $SourceDir |sort lastwritetime -desc |select -skip $limite # | remove-item
@kayasax
kayasax / array2csv.ps1
Created April 13, 2015 08:49
powershell Array collection to CSV
$col=@()
#...
# instead adding an hashtable to the collection, we convert it to psobject
$prop=@{"serveur"="$computername";"nom"="$n";"programme"="$p";"arguments"="$a"; "xml"="$x"}
$col+= new-object -type pscustomobject -property $prop
#this allow us to export data to csv
$r |select serveur,nom,programme, arguments,xml |export-csv -path c:\temp\tasks.csv -notype -delimiter ';' -append
@kayasax
kayasax / substring.ps1
Created March 19, 2015 12:13
Extraire une chaîne de caractères via regex
#exemple pour extraire une adresse IP
$ipaddress=[regex]::match($awsoutput,"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b").Value
@kayasax
kayasax / replace.ps1
Created February 12, 2015 14:45
replace a version number
# replace versionnumber="xxx" whith versionnumber="yyy"
(gc C:\temp\config.xml) -replace '(newversion=)".*"' ,'$1"yyy"' # if you want to save the file add |sc c:\temp\config.xml
@kayasax
kayasax / parameters.ps1
Last active June 14, 2017 11:23
Exemple d'usage de PARAMETER
[CmdletBinding()] #make script react as cmdlet (-verbose etc..)
param(
[Parameter(Position=0, Mandatory=$true,ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$service,
[Parameter(Position=1)]
[System.string]
$computername="local"
@kayasax
kayasax / SchedulerService.ps1
Created September 20, 2013 07:36
Import & export of scheduled tasks using scheduler service
# create task from its xml definition
$sch = New-Object -ComObject("Schedule.Service")
$sch.connect("computername")
$root=$sch.GetFolder("\")
$root.CreateFolder("subfolder")
$folder =$sch.GetFolder("\subfolder")
#import .xml
Get-childItem -path $task_path -Filter *.xml | %{
@kayasax
kayasax / Powershell Script Template.ps1
Last active December 22, 2015 19:39
Template for powershell script. Makes all errors "terminating" and send mail if error occurs
# Templata.ps1
# author: Loic MICHEL
# date: 10/09/2013
# abstract: make all errors terminating errors and send email + raise event in case of failure
#
[CmdletBinding()]param(
)