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 / 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 / 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
-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 / calculatedProperty.ps1
Created September 9, 2015 13:52
Calculated property syntax
Get-ChildItem C:\Test | Select-Object Name, CreationTime, @{Name="Kbytes";Expression={$_.Length / 1Kb}}
@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 / 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 / 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 / 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 / updateWMIProperty.ps1
Created January 7, 2016 14:35
modify wmi property. Key is to use [wmiobject].put() method source https://technet.microsoft.com/en-us/library/ee692805.aspx
$p=gwmi sms_packagebaseclass -Namespace root\sms\site_CT1 |?{$_.packageId -eq "CT1006FA"}
$p.Priority=2
$p.put()
@kayasax
kayasax / ADSI_group_membership.ps1
Created February 2, 2016 10:16
Get group membership with ADSI
([ADSI]"WinNT://$ip/$admingroup,group").psbase.Invoke("Members") |%{
$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
}