Skip to content

Instantly share code, notes, and snippets.

Loïc MICHEL kayasax

  • Colas
  • France
Block or report user

Report or block kayasax

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kayasax
kayasax / replace.ps1
Created Feb 12, 2015
replace a version number
View replace.ps1
# 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 / substring.ps1
Created Mar 19, 2015
Extraire une chaîne de caractères via regex
View substring.ps1
#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 / array2csv.ps1
Created Apr 13, 2015
powershell Array collection to CSV
View array2csv.ps1
$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 / parsingLines.ps1
Created Apr 29, 2015
Comment parser un fichier organisé "en lignes" plutôt qu'en "colonnes"
View parsingLines.ps1
<#
PARSING (log) files.
when log files contains several colums on the same line we can use importfrom-csv
but how to do when log files is organized 'by lines' ?
example
Name: ENC1
IPv4 Address: 172.16.2.101
Link Settings: Forced, 100 Mbit, Full Duplex
Name: ENC2
@kayasax
kayasax / CleanDir.ps1
Created Apr 29, 2015
Conserver les X fichiers plus récents d'un répertoire
View CleanDir.ps1
#combien d'éléments à sauvegarder ?
$limit=5
ls $SourceDir |sort lastwritetime -desc |select -skip $limite # | remove-item
@kayasax
kayasax / legacyapps.ps1
Created Apr 29, 2015
Lancer des exécutables DOS depuis powershell
View legacyapps.ps1
# running dos command with lengthy parameters may sometimes be difficult to run from powershell
# one easy step that may correct the problem is to call cmd.exe /c before calling the command :
# this will not work
# & c:\windows\handle.exe /accepteula .d1 > C:\upf\logs\backup\handle.txt
# this is OK
start-process -Wait -NoNewWindow cmd.exe "/c handle.exe .d1 > C:\upf\logs\backup\handle.txt"
# starting at PS V3.0 we can also use the escape operator : --% ( will stop powershell resolving variables except cmd ones like %computername% )
@kayasax
kayasax / RemoveMultiSpace.ps1
Created Apr 29, 2015
Supprimer les espaces inutiles. Ce code permet de supprimer les successions de 2 espaces ou plus (\s+) en regex
View RemoveMultiSpace.ps1
$text –replace ‘\s+, ‘ ’
@kayasax
kayasax / removeEmptyLines.ps1
Created Apr 29, 2015
Suppression de lignes vides après un split
View removeEmptyLines.ps1
# some ways to remove empty lines when splitting strings
# for example
# $text = "Video Video Audio Audio VBI VBI"
# $text.Split()
# outputs this
# Video
# Video
@kayasax
kayasax / get-mailboxFolders.ps1
Created May 5, 2015
Afficher la liste des dossiers outlook ou trouver le chemin d'accès d'un dossier particulier
View get-mailboxFolders.ps1
# SMAC - LM - 05/05/2015
<#
.Synopsis
Recherche des dossiers dans outlook
Si un nom de dossier est passé en paramètre le script affichera son chemin d'accès,
Si aucun nom n'est fourni, le script liste tous les dossiers outlook
.Description
Utilisation de l'objet COM outlook afin de parcourir les dossiers.
@kayasax
kayasax / remoteUninstall.ps1
Created May 7, 2015
remotely uninstall software
View remoteUninstall.ps1
Hi,
Please try below code:
$app = Get-WmiObject -Class Win32_Product | Where-Object {
$_.Name -match "Software Name"
}
$app.Uninstall()
Please use invoke-command above code to run them on the remote computer, in addition, the below article should be helpful:
Use PowerShell to Find and Uninstall Software
http://blogs.technet.com/b/heyscriptingguy/archive/2011/12/14/use-powershell-to-find-and-uninstall-software.aspx
wershell: Uninstall software on remote computer
You can’t perform that action at this time.