How to Change File Properties (ReadOnly, CreationTime etc.) Using PowerShell

Changing file properties is quite easy with PowerShell.


Remove ReadOnly attribute:


Change CreationTime (90 days back in time):




Easy validating parameter input using ValidateCount, ValidateLength, ValidatePattern, ValidateRange, ValidateSet and ValidateScript in PowerShell

Windows PowerShell introduced parameter validation which drastically reduces lines of validation code – and replaces it with a couple of markup tags:


ValidateCount (int minLength, int maxlength)
How many arguments are allowed for a parameter.

ValidateLength (int minLength, int maxlength)

Length (in characters) of a parameter argument.

ValidatePattern (string regexString, Named Parameters)
Valid patterns for a parameter argument.

ValidateRange (object minRange, object maxRange)
Valid range for a parameter argument.

ValidateSet (string[] validValues, Named Parameters)
Possible values for a parameter argument.

ValidateScript (scriptblock validValues)
Custom script for validation

ValidateNotNull ()
Input is not null

ValidateNotNullOrEmpty ()
Input is neither null or empty


Read more about validating parameters on MSDN:

Or use PowerShell built-in help:


Write Event to Windows Event Log using PowerShell


Creating an EventLog entry using PowerShell is shown below:


Note: The Event Source needs to be created before writing entries to the Event Log. (See this post for further info: Create Event Source with PowerShell)



Create Event Source with PowerShell

To create a Event Source in PowerShell use this:

Get more info on CreateEventSource method here :


In PowerShell 2.0 this is even simpler:


Handling attributes with hyphens in PowerShell

Sometimes we need working with PowerShell objects which have attributes with hyphens. That can be a bit difficult as PowerShell assumes hyphens are used with operators and parameters.

Below is an example on how to get around this, and rename the attribute:





Enumerate COM classes using WMI


Quick and short way of enumerating COM classes is using the WMI class Win32_ClassicComClassSetting.




Fun with Microsoft Agent and PowerShell

Show Merlin:

List animations:


Activate animation:


Have Merlin tell when process was started:


Microsoft Agent is being deprecated and will not be included in future versions of the Windows operating system.

Create shortcut in startup menu using PowerShell