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 / 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(
)
@kayasax
kayasax / decrypt_securestring.ps1
Created September 30, 2015 06:50
decrypt a securestring
$p=read-host "password ?" -assecurestring
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($p)
$clearpassword = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)
see more here
http://stackoverflow.com/questions/7468389/powershell-decode-system-security-securestring-to-readable-password
@kayasax
kayasax / isVM.ps1
Last active September 15, 2015 08:31
Determine if powershell runs within a virtual machine.
function isVM{
(gwmi win32_bios).version -match "vrtual"
}
or (from http://www.windowsnetworking.com/kbase/WindowsTips/Windows7/AdminTips/VirtualPlatforms/UsingPowerShelltodeterminewhetherWindowsisrunninginavirtualmachine.html)
Function isVM {
$objWMI = Get-WmiObject Win32_BaseBoard
@kayasax
kayasax / calculatedProperty.ps1
Created September 9, 2015 13:52
Calculated property syntax
Get-ChildItem C:\Test | Select-Object Name, CreationTime, @{Name="Kbytes";Expression={$_.Length / 1Kb}}
-f Format operator
Format a string expression.
Syntax:
"String with placeholders" -f "Array of values to place into the placeholders"
'Filename: {0} Created: {1}' -f $_.fullname,$_.creationtime
"{I,A:FS} {I,A:FS} {I,A:FS}.." -f "string0", "string1", "string2"...
@kayasax
kayasax / sccm.ps1
Last active August 29, 2015 14:22
powershell SCCM automation
$UIResource = New-Object -ComObject UIResource.UIResourceMgr
#list available software
$UIResource.GetAvailableApplications() | select ID,PackageID,PackageName
#install a soft
$UIResource.ExecuteProgram('*','CT1005EE',$true) # ID, PackageID, execute after download
@kayasax
kayasax / callURL.ps1
Created May 21, 2015 06:30
équivalent de invoke-webrequest pour powershell V2.
$string="http://server/app/index.php?var=val1&var2={0}" -f $event.providerName
(New-Object System.Net.WebClient).DownloadString("$string");
@kayasax
kayasax / remoteUninstall.ps1
Created May 7, 2015 12:14
remotely uninstall software
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
@kayasax
kayasax / get-mailboxFolders.ps1
Created May 5, 2015 09:37
Afficher la liste des dossiers outlook ou trouver le chemin d'accès d'un dossier particulier
# 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 / RemoveMultiSpace.ps1
Created April 29, 2015 10:25
Supprimer les espaces inutiles. Ce code permet de supprimer les successions de 2 espaces ou plus (\s+) en regex
$text –replace ‘\s+ ‘, ‘ ’