Author Archives: chaoliu12

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

Install GUI in Windows 2012 R2 Core

If the regular way failed, then they this way Copy the the C:\Windows\WinSxS from other server with GUI and same updates to C:\WinSxS of Core server Then run the command with -source C:\WinSxS Install-WindowsFeature server-gui-infra,server-gui-shell -source c:\WinSxS

Posted in Windows | Leave a comment

Install Offline standalone CA for Domain

Install standalone CA Change validity period to longer, so it can issue a longer period certificates. certutil -getreg ca\ValidityPeriod certutil -getreg ca\ValidityPeriodUnits certutil -setreg ca\ValidityPeriod “Years” certutil -setreg ca\ValidityPeriodUnits “20” Make standalone CA to support AD.  Don’t joint the standalone … Continue reading

Posted in Windows | 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

Write a GUI in Powershell – Part 1

1. Create XAML interface in Visual Studio.  This will be fast and less coding.  Delete x:class property in Window tag and save the file. Codes: <Window xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221; xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221; xmlns:d=”http://schemas.microsoft.com/expression/blend/2008&#8243; xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006&#8243; xmlns:Collections=”clr-namespace:System.Collections;assembly=mscorlib” x:Name=”window” Title=”Shutdown PC” Height=”436.098″ Width=”544″> <Grid> <Grid.RowDefinitions> <RowDefinition Height=”298*”/> … Continue reading

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