Monday, 10 December 2018

The added value of Azure DevOps for your organization


Two weeks ago Microsoft announced Azure DevOps. Azure DevOps is a name change and rebranding of the product Visual Studio Team Services (VSTS). The Azure DevOps service consists of more than 15 years experience in software development services from TFS (Team Foundation Server) to Visual Studio Online to Visual Studio Team Services to Azure DevOps.
Visual Studio Team Services was linked to Visual Studio by name what was a bit confusing for a lot of organizations. With the name change Microsoft really confirms the fact  that Azure DevOps is a service for every language, framework and platform.

Individual services

Azure DevOps consists of five services that can used simultaneously but also separately:
  • Pipelines: Used to streamline and automate your build and deployment activities (Continuous Integration / Continuous Deployment)
  • Boards: Track tasks and work items using Kanban boards, team dashboards and custom reports.
  • Artifacts: Integration with public and private package feeds such as NuGet, np men Maven
  • Repos: Cloud service for storing and sharing public or private code repositories
  • Test Plans: A service launched with Azure DevOps, that provides a browser-based test management solution for exploratory, planned manual, and user acceptance testing.
Azure DevOps Services
Besides the five separate services the service still has the default overview items like the dashboard and the Wiki.

Added value

The DevOps service can be used where it is really needed. You are able to choose the services that have an added value. The choice for services will not have an impact on the existing (software) development process.
For example, Github is used for code repositories. These repositories can be linked to Pipelines for the build and deployment process.
Another example, is the use of the Boards functionality to plan and follow up tasks, but save the code in another or maybe a existing repository.

How to Write and Run Scripts in the Windows PowerShell ISE


This article describes how to create, edit, run, and save scripts in the Script Pane.

How to create and run scripts

You can open and edit Windows PowerShell files in the Script Pane. Specific file types of interest in Windows PowerShell are script files (.ps1), script data files (.psd1), and script module files (.psm1). These file types are syntax colored in the Script Pane editor. Other common file types you may open in the Script Pane are configuration files (.ps1xml), XML files, and text files.
 Note
The Windows PowerShell execution policy determines whether you can run scripts and load Windows PowerShell profiles and configuration files. The default execution policy, Restricted, prevents all scripts from running, and prevents loading profiles. To change the execution policy to allow profiles to load and be used, see Set-ExecutionPolicy and about_Signing.

To create a new script file

On the toolbar, click New, or on the File menu, click New. The created file appears in a new file tab under the current PowerShell tab. Remember that the PowerShell tabs are only visible when there are more than one. By default a file of type script (.ps1) is created, but it can be saved with a new name and extension. Multiple script files can be created in the same PowerShell tab.

To open an existing script

On the toolbar, click Open, or on the File menu, click Open. In the Open dialog box, select the file you want to open. The opened file appears in a new tab.

To close a script tab

Click the Close icon (X) of the file tab you want to close or select the File menu and click Close.
If the file has been altered since it was last saved, you're prompted to save or discard it.

To display the file path

On the file tab, point to the file name. The fully qualified path to the script file appears in a tooltip.

To run a script

On the toolbar, click Run Script, or on the File menu, click Run.

To run a portion of a script

  1. In the Script Pane, select a portion of a script.
  2. On the File menu, click Run Selection, or on the toolbar, click Run Selection.

To stop a running script

There are several ways to stop a running script.
  • Click Stop Operation on the toolbar
  • Press CTRL+BREAK
  • Select the File menu and click Stop Operation.
Pressing CTRL+C also works unless some text is currently selected, in which case CTRL+C maps to the copy function for the selected text.

How to write and edit text in the Script Pane

You can copy, cut, paste, find, and replace text in the Script Pane. You can also undo and redo the last action you just performed. The keyboard shortcuts for these actions are the same shortcuts used for all Windows applications.

To enter text in the Script Pane

  1. Move the cursor to the Script Pane by clicking anywhere in the Script Pane, or by clicking Go to Script Pane in the View menu.
  2. Create a script. Syntax coloring and tab completion provide a richer editing experience in Windows PowerShell ISE.
  3. See How to Use Tab Completion in the Script Pane and Console Pane for details about using the tab completion feature to help in typing.

To find text in the Script Pane

  1. To find text anywhere, press CTRL+F or, on the Edit menu, click Find in Script.
  2. To find text after the cursor, press F3 or, on the Edit menu, click Find Next in Script.
  3. To find text before the cursor, press SHIFT+F3 or, on the Edit menu, click Find Previous in Script.

To find and replace text in the Script Pane

Press CTRL+H or, on the Edit menu, click Replace in Script. Enter the text you want to find and the replacement text, then press ENTER.

To go to a particular line of text in the Script Pane

  1. In the Script Pane, press CTRL+G or, on the Edit menu, click Go to Line.
  2. Enter a line number.

To copy text in the Script Pane

  1. In the Script Pane, select the text that you want to copy.
  2. Press CTRL+C or, on the toolbar, click the Copy icon, or on the Edit menu, click Copy.

To cut text in the Script Pane

  1. In the Script Pane, select the text that you want to cut.
  2. Press CTRL+X or, on the toolbar, click the Cut icon, or on the Edit menu, click Cut.

To paste text into the Script Pane

Press CTRL+V or, on the toolbar, click the Paste icon, or on the Edit menu, click Paste.

To undo an action in the Script Pane

Press CTRL+Z or, on the toolbar, click the Undo icon, or on the Edit menu, click Undo.

To redo an action in the Script Pane

Press CTRL+Y or, on the toolbar, click the Redo icon, or on the Edit menu, click Redo.

How to save a script

An asterisk appears next to the script name to mark a file that hasn't been saved since it was changed. The asterisk disappears when the file is saved.

To save a script

Press CTRL+S or, on the toolbar, click the Save icon, or on the File menu, click Save.

To save and name a script

  1. On the File menu, click Save As. The Save As dialog box will appear.
  2. In the File name box, enter a name for the file.
  3. In the Save as type box, select a file type. For example, in the Save as type box, select 'PowerShell Scripts (*.ps1)'.
  4. Click Save.

To save a script in ASCII encoding

By default, Windows PowerShell ISE saves new script files (.ps1), script data files (.psd1), and script module files (.psm1) as Unicode (BigEndianUnicode) by default. To save a script in another encoding, such as ASCII (ANSI), use the Save or SaveAs methods on the $psISE.CurrentFile object.
The following command saves a new script as MyScript.ps1 with ASCII encoding.
PowerShell
$psISE.CurrentFile.SaveAs("MyScript.ps1", [System.Text.Encoding]::ASCII)
The following command replaces the current script file with a file with the same name, but with ASCII encoding.
PowerShell
$psISE.CurrentFile.Save([System.Text.Encoding]::ASCII)
The following command gets the encoding of the current file.
PowerShell
$psISE.CurrentFile.encoding
Windows PowerShell ISE supports the following encoding options: ASCII, BigEndianUnicode, Unicode, UTF32, UTF7, UTF8, and Default. The value of the Default option varies with the system.
Windows PowerShell ISE doesn't change the encoding of script files when you use the Save or Save As commands.

See Also

IMPROVE YOUR POWERSHELL SCRIPTS WITH THESE 2 EASY WAYS TO HANDLE ERRORS

IMPROVE YOUR POWERSHELL SCRIPTS WITH THESE 2 EASY WAYS TO HANDLE ERRORS

When creating PowerShell scripts, you must be aware that the person who is going to execute them may not have the same technological knowledge that you have. A key point is that they don't know how the script was designed and its flow. And on top of that, we are all humans and we are prone to make mistakes. It’s a recipe for what you believe is a perfectly written script to somehow go wrong.

Windows PowerShell Scripting Tutorial for Beginners


Automate it. Now, where’s that script…Warning: PowerShell is addictive.

Meet PowerShell Tutorial

Windows PowerShell is an object-oriented automation engine and scripting language with an interactive command-line shell designed to help IT professionals configure systems and automate administrative tasks. You can find it in every modern Windows OS starting with Windows 2008R2. Learning Windows PowerShell is like learning to use a universal multi-tool. In this post, I cover PowerShell scripting basics so you can more easily perform virtually any administration task related to your Windows IT environment.
So let’s start learning PowerShell.
PowerShell offers both a command-line option and an integrated scripting environment (ISE):
  • To launch the PowerShell command line, type powershell.exe  in the Windows Start menu. You’ll see a screen like the following:
  • To launch the PowerShell ISE, type powershell_ise.exe  in the Start menu. Using the PowerShell ISE is the preferred way to work with the scripting language, because it provides syntax highlighting, auto-filling of commands and other automation features that simplify script development and testing.

Preparing to Run PowerShell Scripts

PowerShell scripts are stored in.ps1 files. By design, you cannot run a script by simply double-clicking a file; this helps avoid accidental harm to your systems. Instead, to execute a script, right-click it and click “Run with PowerShell”:
In addition, there is policy that restricts script execution. You can check this policy by running the Get-ExecutionPolicy command in PowerShell:
You will get one of the following values:
  • Restricted— No scripts are allowed. This is the default setting, so you will see it the first time you run the command.
  • AllSigned— You can run scripts signed by a trusted developer. With this setting in place, before executing, a script will ask you to confirm that you want to run it.
  • RemoteSigned— You can run your own scripts or scripts signed by a trusted developer.
  • Unrestricted— You can run any script you want.
To start working with PowerShell, you’ll need to change the policy setting from Restricted to RemoteSigned using the Set-ExecutionPolicy RemoteSigned command:

PowerShell Cmdlets

About Cmdlets

A cmdlet is a PowerShell command with a predefined function, similar to an operator in a programming language. Here are some key things to know about cmdlets:
  • There are system, user and custom cmdlets.
  • Cmdlets output results as an object or as an array of objects.
  • Cmdlets can get data for analysis or transfer data to another cmdlet using pipes (I’ll discuss pipes more in a moment).
  • Cmdlets are case-insensitive. For example, it doesn’t matter whether you type “Get-ADUser”, “get-aduser” or “gEt-AdUsEr”.
  • If you want to use several cmdlets in one string, you must separate them with a semicolon (;).

Cmdlet Format

A cmdlet always consists of a verb (or a word that functions as a verb) and a noun, separated with a hyphen (the “verb-noun” rule). For example, some of the verbs include:
  • Get — To get something
  • Set — To define something
  • Start — To run something
  • Stop — To stop something that is running
  • Out — To output something
  • New — To create something (“new” is not a verb, of course, but it functions as one)
For practice, try executing the following cmdlets:
  • Get-Process — Shows the processes currently running on your computer:
  • Get-Service — Shows the list of services with their status
  • Get-Content — Shows the content of the file you specify (for example, Get-ContentC:\Windows\System32\drivers\etc\hosts)

Available Cmdlets

Good news — you don’t need to memorize all cmdlets. You can list all cmdlets by executing the Get-Help -Category cmdlet, which will return the following:
You can also create your own custom cmdlets.

Parameters

Each cmdlet has several parameters that customize what it does. The PowerShell ISE will automatically suggest all valid parameters and their types after you type a cmdlet and a hyphen (-):
For example, the following cmdlet shows all services whose names start with “W”:
Get-Service -Name W*
If you forget a cmdlet’s parameters, just use a script like the following, which will display the parameters for the Get-Process cmdlet:
Get-Process | Get-Member
If you still don’t find the cmdlet you need, you can make sure the help is current and then get examples for a cmdlet (such as Get-Process) using a script like this:
Update-Help #to update the help data
Get-Help Get-Process -Examples

Aliases

You can also use aliases, which are shortened cmdlet names. For instance, instead of “Get-Help” you can use just “Help”. Try running the following two commands and see whether you get the same result:
  • Start-Process notepad
  • start notepad
Similarly, to stop this process, you can use either of the following commands:
  • Stop-Process -Name notepad
  • spps -Name notepad
To see all aliases, execute the Get-Alias cmdlet.

Comments

Leaving comments in a script will help you — and your colleagues — better understand what the script does. A string comment is a single line that starts with a number sign (#), and block comments start and end with number signs and angle brackets and spread across multiple lines.

Pipes

A pipe passes data from one cmdlet to another. I used a pipe earlier to get all properties of an object.
For example, if you execute the following script, you’ll get all services sorted by their status:
Get-Service | Sort-Object -property Status
You can also use a pipe to output text to a file using a script like the following:
"Hello, World!" | Out-File C:\ps\test.txt
You can use multiple pipes. For instance, the following script lists all services, with the first pipe excluding stopped services and the second pipe limiting the list to display names only:
Get-Service | WHERE {$_.status -eq "Running"} | SELECT displayname
# “$_.” defines current element in the pipe

Summary

Let’s quickly summarize the key points of this Windows PowerShell tutorial. Now you know how to run PowerShell, how to change execution policy, what a cmdlet is, how to pass data using pipe and how to get object properties. Keep in mind that if you forget something, you can always use the Get-Help cmdlet.
I hope you found this PowerShell for beginners useful!
In the next parts of this free PowerShell tutorial, I’ll cover variables, arrays and cycles, which are used in PowerShell scripting to simplify the administration of Windows Servers.
In the meantime, you might want to check out the following PowerShell scripts used by IT professionals to address specific cases:
  1. How to Get AD User Group Membership Reports
  2. How to Find Disabled or Inactive Users in Active Directory
  3. How to Find Inactive Computers in Active Directory
  4. How to Get a List of Expired User Accounts in AD
  5. How to Find Locked Out User Accounts in Active Directory
  6. How to List All User Accounts on a Windows System
And if you are just getting started with PowerShell, I recommend the following resources: