PowerShell Playbook

This is my private PowerShell playbook.

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)
$doublequote = "`""
$FullPath2LanguagePackQuoted = $doublequote+$FullPath2LanguagePack+$doublequote
Invoke-expression  "C:\Windows\System32\Dism.exe /Online /Add-Package /PackagePath:$FullPath2LanguagePackQuoted

2. Get to know if my process is running in 64bit
$PSenvIs64bit=[Environment]::Is64BitProcess    (brings back False or True)

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 !!!

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:


A. Best extension ever for Powershell ISE "iseSteroids"

No comments:

Post a Comment