Category Archives: Powershell

Get-ADObject Filter vs LDAP Filter

Get-ADObject Filter Definition: <filter> ::= “{” <FilterComponentList> “}” <FilterComponentList> ::= <FilterComponent> | <FilterComponent> <JoinOperator> <FilterComponent> | <NotOperator> <FilterComponent> <FilterComponent> ::= <attr> <FilterOperator> <value> | “(” <FilterComponent> “)” <FilterOperator> ::= “-eq” | “-le” | “-ge” | “-ne” | “-lt” | “-gt”| … Continue reading

Posted in Active Directory, Powershell | Leave a comment

Write a GUI in Powershell – Part 7

7. Finish every else in Powershell. This script will run the timer. Once the time is reached, it will run the command. # (C) Chao Liu #=========================================================================== # Add CSharp Class to PowerShell #=========================================================================== $path=$PSScriptRoot $code=Get-Content -Raw -Path (Join-Path $path … Continue reading

Posted in C#, Powershell, XAML | Leave a comment

Write a GUI in Powershell – Part 6

6a. This is the last C# class. This class will call function in Kernel.dll and PowrProf.dll to get power info. using System; using System.Diagnostics; using System.Runtime.InteropServices; namespace PowerManagerNS { //public Guid GUID_SLEEP_SUBGROUP = new Guid(“238C9FA8-0AAD-41ED-83F4-97BE242C8F20”); public static class PowerManager { … Continue reading

Posted in C#, Powershell, XAML | Leave a comment

Write a GUI in Powershell – Part 5

5a. Create an other C# class using System; using System.ComponentModel; using System.Globalization; using System.Windows.Data; using System.Management.Automation; public class MultiValueConverterWrap : IMultiValueConverter { public Func<object[], Type, object, CultureInfo, PSObject> ConvertPS; public Func<object, Type[], object, CultureInfo, PSObject> ConvertBackPS; public int debugLevel = … Continue reading

Posted in C#, Powershell, XAML | Leave a comment

Write a GUI in Powershell – Part 4

4a. Create converter in C# for data binding for the same reason, Powershell doesn’t support C# interface. using System; using System.ComponentModel; using System.Globalization; using System.Windows.Data; using System.Management.Automation; public class ConverterWrap : IValueConverter { public Func<object, Type, object, CultureInfo, PSObject> ConvertPS; … Continue reading

Posted in C#, Powershell, XAML | Leave a comment

Write a GUI in Powershell – Part 3

3a. Create data module in C#, This is useful when doing data binding. Don’t know if Powershell is able to create a custom object inherit a C# interface. But Powershell can use Add-Type to add a C# class. Then we … Continue reading

Posted in C#, Powershell, XAML | Leave a comment

Write a GUI in Powershell – Part 2

2. Convert XAML to powershell [void][System.Reflection.Assembly]::LoadWithPartialName(‘presentationframework’) [xml]$xaml = Get-Content -Raw -Path (Join-Path $path “autoshutdown.xaml”) #Read XAML $reader=(New-Object System.Xml.XmlNodeReader $xaml) try{$Form=[Windows.Markup.XamlReader]::Load( $reader )} catch{Write-Host “Unable to load Windows.Markup.XamlReader. Some possible causes for this problem include: .NET Framework is missing PowerShell must … Continue reading

Posted in C#, Powershell, XAML | Leave a comment