Function to prepare Machine.config

This PowerShell script “prepare” machine.config by:

  • Create appSettings.config and link it in machine.config
  • Create connectionStrings.config and link it in machine.config
  • Add proxy settings

Code:

 

 

 

 

 

 

PowerShell new features.

PowerShell 5.0 (Windows Management Framework 5.0)

  • By default in Windows 10 & Windows Server 2016 Technical Preview.
  • Remote Script Debugging in ISE 🙂
  • Transcription works in ISE by default
  • .NET enumerations.
  • Improved DSC.

PowerShell 4.0

  • By default in Windows 8.1 & Windows Server 2012 R2
  • DSC: Desired State Configuration
  • Remote Script Debugging in console (no ISE)
  • Improved Invoke-RestMethod and Invoke-WebRequest to specify headers.

PowerShell 3.0

  • By default in Windows 8 & Windows Server 2012
  • Improved ISE: IntelliSense
  • Improved remote PowerShell ( New-PSSession)
  • Module Auto-Load
  • Invoke-RestMethod and Invoke-WebRequest
  • Ordered Hashtables
  • Scheduled jobs

PowerShell Modules: All you need to remember

 

Script Modules

A script module is a file (.psm1) that contains any valid Windows PowerShell code. Script developers and administrators can use this type of module to create modules whose members include functions, variables, and more.

Binary Modules

A binary module is a .NET Framework assembly (.dll) that contains compiled code. Cmdlet developers can use this type of module to create modules that contain cmdlets, providers, and more. (Existing snap-ins can also be used as binary modules.)

Manifest Modules

A manifest module is a module that includes a manifest (described later in this section) to describe its components, but that does not specify a root module in the manifest. A module manifest does not specify a root module when the ModuleToProcess key of the manifest is blank. In most cases, a manifest module also includes one or more nested modules using script modules or binary modules. A manifest module that does not include any nested modules can be used when you want a convenient way to load assemblies, types, or formats.

Dynamic Modules

A dynamic module is a module that does not persist to disk. This type of module enables a script to create a module on demand that does not need to be loaded or saved to persistent storage. By default, dynamic modules created with the New-Module cmdlet (described in the following sections) are intended to be short-lived and therefore cannot be accessed by the Get-Module cmdlet

Using Transfer utility in AWS SDK.NET

Useful Links

Upload files

Upload directory

 

 

Function to change encoding of a file in PowerShell

This is a function to change encoding of a file:

Function to check if MarkLogic is up

Function to quickly see if MarkLogic is up and running

Taken from my unsuccessful StackOverflow answer 🙂

 

Function to SmartCreate Folder in Powershell

Function to create a folder in Powershell if it doesn’t exist or recreate if it exists

 

Execute function in remote Computer

This is an example of how to execute PowerShell remote code and pass parameters:

Function to SmartCreate Network Share in Powershell

This is a function to create a readonly Network Share if it doesn’t exist.

How to fix PowerShell remoting not working

If Powershell remoting is not working between two servers check this:

  • Check if winrm service is running. Full name is Windows Remote Management (WS-Management)
  • Execute winrm quickconfig
  • Enable-PSRemoting -Force command on server.
  • Get-ExecutionPolicy -List to check that you can execute…
  • Check that winrm port is the same as listener port
    • Winrm port: winrm get winrm/config
    • Listener port: winrm enumerate winrm/config/listener
    • Change listener port by (from elevated cmd!!!):
      Winrm set winrm/config/listener?Address=*+Transport=HTTP @{Port=”5985″}
  • Check Windows Firewall is not blocking port.
  • Check that choosen port (5985 or 81) is open (Cryping, NMap)
  • Check TrustedHosts list
  • Test with Invoke-Command -ComputerName SERVER -Port 5985 -ScriptBlock {“C:\Program files” |  Get-ChildItem}
  • Test Invoke-Command with Credentials