My PowerShell Scripts Repository
Write-PSscripts | Blog-Them
Powerquery is … powerfull !!
Posted by on July 27, 2014
This is definitly not directly related to PowerShell, but I have to note it somewhere 🙂
Here are some Powerquery samples to parse 4624 events :
SecurityID:
Text.Range(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Security ID:”, Occurrence.Last)+14),0,Text.PositionOf(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Security ID:”, Occurrence.Last)+14),”#(cr)”, Occurrence.First))
AccountName:
Text.Range(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Account Name:”, Occurrence.Last)+15),0,Text.PositionOf(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Account Name:”, Occurrence.Last)+15),”Account Domain:”, Occurrence.First))
AccountDomain:
Text.Range(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Account Domain:”, Occurrence.Last)+17),0,Text.PositionOf(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Account Domain:”, Occurrence.Last)+17),”Logon ID:”, Occurrence.First))
WorkstationName:
Text.Range(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Workstation Name:”, Occurrence.Last)+18),0,Text.PositionOf(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Workstation Name:”, Occurrence.Last)+18),”Source Network Address:”, Occurrence.First))
SourceNetworkAddress:
Text.Range(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Source Network Address:”, Occurrence.Last)+24),0,Text.PositionOf(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Source Network Address:”, Occurrence.Last)+24),”Source Port:”, Occurrence.First))
LogonProcess:
Text.Range(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Logon Process:”, Occurrence.Last)+16),0,Text.PositionOf(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Logon Process:”, Occurrence.Last)+16),”Authentication Package:”, Occurrence.First))
AuthentificationPackage:
Text.Range(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Authentication Package:”, Occurrence.Last)+24),0,Text.PositionOf(Text.RemoveRange([Message],0,Text.PositionOf([Message],”Authentication Package:”, Occurrence.Last)+24),”Transited Services:”, Occurrence.First))
AdminSDHolder protected objects
Posted by on October 16, 2012
Want to know which groups or users are protected throuh AdminSDHolder process ?
You can have a look to the protected groups with the following commands:
| Get-ADgroup -LDAPFilter “(admincount=1)” | select name,SID |
And here is the one for the users:
| Get-ADuser -LDAPFilter “(admincount=1)” -Properties * | select name, memberOf |
HTH!
Just a last thing… D Day is coming in 10…
Deploy a Data Collector Set to domain controllers of several forests…
Posted by on October 11, 2012
I’ve created a new data collector set for my domain controllers, and I want now to be able to deploy it broadly.
So I’ve created a Powershell script to deploy it to all domain controllers in several forests or domains. Please notice this is a first released version, and there is no error management yet. The script will copy the xml file to the destination server (directly on c$, need also to improve that!), and then will add it as a DCS. You need WinRM to be enabled on your servers (winrm quickconfig). Obviously, you’ll need permissions to deploy DCS to domain controllers (I made my test being added to Administrators group of each domain I used.)
As an input for my script, you’ll need to provide the XML template, so you’ll need to export it as a template, through the Performance Monitor GUI.
Once you have the XML file, you’’ll need to customize the script to provide the forests you want to deploy it, customizing the following line:
|
$forests = @(“forest1.ext,forest2.ext,forest3.ext”) |
Once you’ve done that, you can also notice I use a default DCS for my test in the following line:
|
$DCSxmltemplate = “C:\DCS\DCS-DomainControllers-V1.2.xml” |
You should remove the default value and set the parameter mandatory.
And…here is the script:
|
<# ### Test for variables ### Work with variables write-host “— Script Info —“ ### Load Module ### Add support for all forests ### Get Domain Controllers List ### Script ### Overall Timing |
HTH, I’ll update this one with several improvements soon (Error management, Temp folder customization…)
Here are 2 useful links to help dealing with DCS and PowerShell:
Want your Script tells you everything is ok ?
Posted by on April 13, 2012
Yes, you can ! PowerShell is able to use the Speech API and to tell you everything you want. Here is how:
|
$VoiceObj = new-object -com SAPI.SpVoice |
You want to read the txt output file just generated ? You can:
|
$VoiceObj = new-object -com SAPI.SpVoice |
Windows 8–PowerShell ISE is… so cool !
Posted by on March 11, 2012
What a nice surprise when launching ISE on my W8 laptop:
That just rocks… I looked then for more information about new features and capabilities of the new ISE, and the list is long, trust me… or go have a look here “Windows PowerShell ISE v3.0, Now with Extra AWESOME!”.
Another reason to install Windows 8 !

Add a get-help feature to your own scripts
If you want to share your scripts (or reuse them several months later), you’ll need to add comments and description into the code. To be consistent, you can use the built-in help provided by PowerShell.
You only need to add a block comment on the beginning of the script, and use the following section keywords:
You can have a look to the output of the help about_comment_based_help command to get more information. I also encourage you to read the following post from Don Jones : WTFM: Writing the Fabulous Manual
He is an example:
<#
.SYNOPSIS
Retrieves service pack and operating system information from one or more remote computers.
.DESCRIPTION
The Get-Inventory function uses Windows Management Instrumentation (WMI) toretrieve service pack version, operating system build number, and BIOS serial number from one or more remote computers.
Computer names or IP addresses are expected as pipeline input, or may bepassed to the –computerName parameter.
Each computer is contacted sequentially, not in parallel.
.PARAMETER computerNameAccepts
a single computer name or an array of computer names. You mayalso provide IP addresses.
.PARAMETER path
The path and file name of a text file. Any computers that cannot be reached will be logged to this file.
This is an optional parameter; if it is notincluded, no log file will be generated.
.EXAMPLE
Read computer names from Active Directory and retrieve their inventory information.
Get-ADComputer –filter * | Select{Name="computerName";Expression={$_.Name}} | Get-Inventory.
.EXAMPLE
Read computer names from a file (one name per line) and retrieve their inventory information
Get-Content c:\names.txt | Get-Inventory.
.NOTES
You need to run this function as a member of the Domain Admins group; doing so is the only way to ensure you have permission to query WMI from the remote computers.
#>
HTH.