[hemmerling] Scripting Languages for Windows 2/3 - Windows PowerShell

Windows PowerShell - Software

Windows PowerShell 5 - Download for Win7, Win8.1

Windows PowerShell 4 - Download for Win7

Windows PowerShell 5 - Download for Win7

Development Tools

XAML Tools

Online Development Tools

How to Write PowerShell Code, and C# Code for PowerShell

Development of Cmdlets

General

Help for PowerShell Cmdlets

Development of Windows PowerShell Modules in C#

Tools & Frameworks

Loading of PowerShell Modules

DLL Development

Load a Custom DLL from PowerShell
Resources

Development of Windows Services by Windows PowerShell

Development of Windows Services by Windows PowerShell, with little help by the "Windows Server 2003 Resource Kit Tools" srvany.exe and instsrv.exe

Development of Windows Services by Windows PowerShell and C#

Tools, Frameworks, Technologies

BloodHound

  • GitHub "BloodHoundAD/BloodHound" - “BloodHound is a single page Javascript web application, built on top of Linkurious, compiled with Electron, with a Neo4j database fed by a PowerShell ingestor. BloodHound uses graph theory to reveal the hidden and often unintended relationships within an Active Directory environment”.

Desired State Configuration ( DSC ) of Windows

Psake - Build Manager

  • EN.Wikipedia "Psake" - “A domain-specific language and build automation tool written in PowerShell to create builds using a dependency pattern similar to Rake or MSBuild. It dramatically simplifies the build language as compared to MSBuild scripting”.

Generation of PowerShell GUI Applications with WPF

The discontinued PowerBoots
ShowUI, the Successor of PowerBoot
Resources

Package Manager & Repositories

  • There are
    1. Package repositories ( in the Clowd ).
    2. Package provider.
    3. Package manager ( on the local PC, do almost nothing, at least not “packaging” ).
Galleries / Repositories
Chocolatey
NuGet
OneGet & PowerShellGet
PSGet

PowerShell Remoting

PowerShell for SQL Server

PowerShell Testing

Windows PowerShell Tips & Tricks

  • Best training strategy, according to PowerShell experts:
    1. First learn how to use PowerShell for Windows system administration.
    2. Afterwards, you may also learn how to use PowerShell as a Window developer.
  • Run “start /w aCommand” to get the script prompt back after the execution of the command “aCommand” is finished. Else the prompt returns immediately and the shell does not wait for completion of the execution of “aCommand”.
  • The most important commands :-) for rookies:
    1. PowerShell command “get-command”.
    2. PowerShell command “get-help”.
    3. Application “powershell_ise.exe”.
    4. Since PowerShell 3, help must be installed manually, by “Update-Help -force -verbose UIculture de-DE”, Update-Help -UICulture 'en-US'.
  • There are 2 levels of compatibility
Version .NET Compatibility Operating System Comments
Powershell 1 .NET 2.0 1 & 2 WinXP outdated
Powershell 2 .NET 2.0, .NET 3.5 WinXP supported
Powershell 3 .NET 4.0, .NET 4.5 3 & 4 Win7, Win8 supported
Powershell 4 .NET 4.0, .NET 4.5 Win7, Win8.1 supported, can't be installed on Win8
Powershell 5 ? Win7, Win2012, Win8.1, Win10 supported
  • Redirection:
    • In opposite to the Linux / Unix shells, e.g. Bourne Shell, there is no input redirection, even with “Powershell 5” :-(.
    • Full output redirection was a lately implemented feature of Powershell :-).
    • Remember that with output redirection, not plain text, but objects are returned - that's much more than available with Bourne Shell or other text-based input redirection.
    • How to redirect StdErr with PowerShell: “application.exe 2>&1 >saved_stderr.txt”.
  • Stack Overflow "How to start PowerShell from Windows Explorer?" - “In Windows Explorer, just go to the Address Bar at the top (keyboard shortcut: Alt+D) and type powershell and press Enter. A PowerShell command window opens with the current directory”.
  • If you don´t own Win8.1 or Win2012Server, you don´t get the latests high-level functions. On Win7 and Win2008Server, if you want do implement the missing high-level functions by your own, you have to write .NET software in C#.
    • Unfortunately, the names of methods you need are not mentioned in the PowerShell documentation. Instead, you have to find it in the .NET and WPL documentation, by yourself!
    • It is challenging to get names of methods you want to use, by the .NET and WPL documentation.
  • PowerShell Execution Policies.
    • I myself like to create and use a batch file “powershell_unrestricted.ps1” with the contents “PowerShell.exe -ExecutionPolicy Unrestricted” :-) to work without restrictions.
  • File location:
    • Modules:
      • Powerscript modules are located in subdirectories of the Windows directory “C:\Windows\System32\WindowsPowerShell\v1.0\Modules”.
      • You may open your modules directory with PowerShell by “explorer.exe ($PSHOME | Join-Path -ChildPath Modules)”.
    • Autoexec files ( e.g. <user> = “Administrator” ). If you refer to other files in the directory, you have to specify the full absolute path to it!
      • “C:\Users\Administrator\Documents\WindowsPowerShell”.
        • “C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1”.
        • “C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1”.
  • Reset.
  • My experience with ISE “caching” of old files ( see StackOverflow "Windows PowerShell ISE running old version" ):
    • The behaviour of ISE is different for PS modules ( .psm1 ) and simple PS scripts ( ps1 ). I am using PS&ISE with Win10Pro.
      • My experience with modules ( .PSM1 )
        1. Load a module file “hello.psm1” already placed in a proper module directory ( e.g. “C:\Users\MyUserName\Documents\WindowsPowerShell\Modules\Hello” ) by ISE.
        2. Execute a function by “Run Selection” ( you may not execute modules by “Run Script” ).
        3. Modify the file, e.g. the output of the function 'Write-Host “Hello World!”' to 'Write-Host “Hello”' and save the file.
        4. Execute a function by “Run selection”, and it will execute the old function, with old output, e.g. “Hello World!”. This is also true if I repeat the “Run Selection” command.
        5. Just if I leave ISE and load it again, the new function is executed by “Run Selection”.
      • My experience with scripts ( .PS1 ).
        1. If I execute “Run Selection”, the same behaviour as with modules.
        2. If I execute once “Run Script” and by that the function is called, the current version of the function is executed. Of course I call the function ( e.g. on line number 100 ) in the file “after” it is defined ( e.g. in lines 10-20 ). By this, there is no caching.
        3. Especially and consequently, if I execute once “Run Script”, while the executed code doesn't call the function, and then execute my function by “Run Selection”, the current version of the function is executed.
      • Here is my workaround to make module development more comfortable:
        • Simple scripts may be executed by “Run script”.
        • If I want to develop a module ( .PSM1 ), I name it as simple script ( .PS1 ) during the development phase. I place the file ( e.g. “hello.ps1” ) already in the proper module folder, e.g. “C:\Users\MyUserName\Documents\WindowsPowerShell\Modules\Hello” for a module “Hello”. Of course by this I can´t execute the functions as module functions from PowerShell console. I just want to use ISE to call functions for testing.
        • As modules are not executed as script, there is no executable code in the file, but just functions ( AFAIK ). So I may safely execute a “Run Script” on my script.
        • So if I modify a module file under ISE development, I always first execute “Run Script”, before I execute a function by “Run Selection”. By this I always execute the current version of a function.
  • How to get a static variable which is not reset by calling a new PS script:
    • Function:
      $a=1
      $code={
          $scipt:a++
          $a
      } GetNewClosure()
      
    • Call: ”&$code”
    • Output: 1234567

Windows Powershell Projects

Windows Powershell Resources

Microsoft

PowerShell Links for Developers

Powershell Testing

The Script Language

General


When this document changes ! Site Navigation ( My Business ! My Topics ! Imprint / Contact ! Privacy Policy ! Keyword Index ! ! Google+ Publisher "hemmerling" )

 
en/wscripting02.html.txt · Last modified: 2017/12/11 17:55 (external edit) · []
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki