Translate

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 = "`""
Example:
$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.
 %windir%\SysWoW64\cmd.exe

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
https://blogs.msdn.microsoft.com/virtual_pc_guy/2010/09/23/a-self-elevating-powershell-script/



6a. SystemAccount (SCCM Client) modifies all users profile (RegKeys)
    (Load Hive Keys WAY runs before loading)
http://www.adminarsenal.com/admin-arsenal-blog/modifying-the-registry-users-powershell/

6b. SystemAccount (SCCM Client) modifies all users profile (RegKeys)
    (More Elegant WAY runs with Active Setup Part)
https://gallery.technet.microsoft.com/scriptcenter/Easily-set-a-registry-b3449784
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
http://www.darkoperator.com/blog/2013/3/5/powershell-basics-execution-policy-part-1.html

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)
MS VPN:
Get-VpnConnection | Select Name, ConnectionStatus

MS DirectAccess:
Get-DAConnectionStatus

3rd Party VPNs detect:
https://gallery.technet.microsoft.com/scriptcenter/Test-VPNConnection-Check-36fa4b57


TOOLS

A. Best extension ever for Powershell ISE "iseSteroids"
http://www.powertheshell.com/isesteroids/





No comments:

Post a Comment