PowerShell Playbook

This is my private PowerShell playbook. (Update 07/2020)

REMARK: Using the new blogger UI updating this page corrupted it! So do not rely on these informations in the moment. I am in contact with Google to get this fixed!
Some sort of unstructured but very helpful hints to fix PowerShell related Stuff. Some stuff I found on other places in the web and it just helps me when creating my own scripts.

Tips and Tricks

1. Case of the DoubleQuote (When you need to pass variables containing spaces or other strange characters)

2. Get to know if my process is running in 64bi

3. For testing on a 64bit machine you want to test the setup with the setup environment of SCCM client which is 32bit.

4. Excecute a 64bit Powershell from a 32bit process (SCCM Client)

%windir%\Sysnative\windowsPowershell\V1.0\PowerShell.exe -NoProfile -ExecutionPolicy Bypass -file %~dp0MyScript.ps1

5. Execute a self elevating Powershell Script

6a. SystemAccount (SCCM Client) modifies all users profile (RegKeys)
    (Load Hive Keys WAY runs before loading)

6b. SystemAccount (SCCM Client) modifies all users profile (RegKeys)
    (More Elegant WAY runs with Active Setup Part)
NOTE on Win10 need to be fixed (Double Active Setup Entries in the same root!!! This is like pregnant fathers. Impossible but true!!!) Seems to be a BUG in WINDOWS 10 !!!
Also noted that MS recently mentioned that Active Setup should not be used for other 3rd Party setups!!!!

7. Easy way to implement PowerShell Code Signing

8. Figure out the OS Language with .Net in Powershell
$SystemLanguage =[CultureInfo]::InstalledUICulture
may result e.g. in en-US or de-DE or other combinations.

9. To get out if having VPN connections (MS Builtin VPNs)
Get-VpnConnection | Select Name, ConnectionStatus

MS DirectAccess:

3rd Party VPNs detect:

10. Differences between 10 ways of starting an executable or external process

11. Call a Win32 API from Powershell (Example Code)

$MethodDefinition = @’
[DllImport(“kernel32.dll”, CharSet = CharSet.Unicode)]
public static extern bool
$Kernel32 = Add-Type -MemberDefinition $MethodDefinition -Name ‘Kernel32’ -Namespace ‘Win32’ -PassThru

# You may now call for example the CopyFile function with its
# arguments in brackets. For arguments check please API
# documentation on Which you also need for
# the argument definition above which is also highlighted!
# Copy calc.exe to the user’s desktop


12. Clever handling with services. 

Better to use .NET integrated functions directly from PowerShell.
In this example we stop a service, wait for finishing before we continue. The trick is the .WaitForStatus. This eleminates the need for a wile loop.

$ccmexecservice = [System.ServiceProcess.ServiceController]::new('ccmexec')


A. Best extension ever for Powershell ISE "iseSteroids"