concept Microsoft in category powershell

appears as: Microsoft, Microsoft
Learn PowerShell in a Month of Lunches

This is an excerpt from Manning's book Learn PowerShell in a Month of Lunches.

Microsoft offers two products with very similar names that are completely different (The saying is true – There are 2 hard problems in tech: cache invalidation, naming things, and off-by-1 errors). The first product is one you might have heard of: Visual Studio. It’s a full-featured Integrated Development Environment (IDE). It’s typically used by C# and F# developers. Visual Studio Code, on the other hand, is a completely different application. It’s a lightweight text editor that has some resemblance to other text editors like Sublime Text, Notepad++, except that it has some added features to enhance the experience.

One of PowerShell’s primary strengths is its extensibility. As Microsoft continues to invest in PowerShell, it develops more and more commands for products including Azure Compute (Virtual Machines), Azure SQL, Azure Networking, Azure DNS, and so on. You typically manage these through the Azure portal, and we will discuss how to install the Azure PowerShell modules later in this chapter.

PARAMETERS
    -DefaultProfile <Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer>
        The credentials, account, tenant, and subscription used for communication with azure
 
        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?       False
        Accept wildcard characters?  false
 
    -EnabledForDeployment <System.Management.Automation.SwitchParameter>
        Enables the Microsoft.Compute resource provider to retrieve secrets from this key vault when this key vault is referenced in resource creation, for example when creating a virtual machine.
 
        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?       True (ByPropertyName)
        Accept wildcard characters?  false
 
    -EnabledForDiskEncryption <System.Management.Automation.SwitchParameter>
        Enables the Azure disk encryption service to get secrets and unwrap keys from this key vault.
 
        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?       True (ByPropertyName)
        Accept wildcard characters?  false
 
    -EnabledForTemplateDeployment <System.Management.Automation.SwitchParameter>
        Enables Azure Resource Manager to get secrets from this key vault when this key vault is referenced in a template deployment.
 
        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?       True (ByPropertyName)
        Accept wildcard characters?  false
 
    -EnablePurgeProtection <System.Management.Automation.SwitchParameter>
        If specified, protection against immediate deletion is enabled for this vault; requires soft delete to be enabled as well.
 
        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?       False
        Accept wildcard characters?  false
 
    -EnableSoftDelete <System.Management.Automation.SwitchParameter>
        Specifies that the soft-delete functionality is enabled for this key vault. When soft-delete is enabled, for a grace period, you can recover this key vault and its contents after it is deleted. For more information about this
        functionality, see Azure Key Vault soft-delete overview (https://docs.microsoft.com/azure/key-vault/key-vault-ovw-soft-delete). For how-to instructions, see [How to use Key Vault soft-delete with
        PowerShell](https://docs.microsoft.com/azure/key-vault/key-vault-soft-delete-powershell).
 
        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?       False
        Accept wildcard characters?  false
 
    -Location <System.String>
        Specifies the Azure region in which to create the key vault. Use the command Get-AzLocation (https://docs.microsoft.com/powershell/module/Azure/Get-AzLocation)to see your choices.
 
        Required?                    true
        Position?                    2
        Default value                None
        Accept pipeline input?       True (ByPropertyName)
        Accept wildcard characters?  false
 
    -Name <System.String>
        Specifies a name of the key vault to create. The name can be any combination of letters, digits, or hyphens. The name must start and end with a letter or digit. The name must be universally unique.
 
        Required?                    true
        Position?                    0
        Default value                None
        Accept pipeline input?       True (ByPropertyName)
        Accept wildcard characters?  false
 
    -ResourceGroupName <System.String>
        Specifies the name of an existing resource group in which to create the key vault.
 
        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?       True (ByPropertyName)
        Accept wildcard characters?  false
 
    -Sku <Microsoft.Azure.Management.KeyVault.Models.SkuName>
        Specifies the SKU of the key vault instance. For information about which features are available for each SKU, see the Azure Key Vault Pricing website (https://go.microsoft.com/fwlink/?linkid=512521).
 
        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?       True (ByPropertyName)
        Accept wildcard characters?  false
 
    -Tag <System.Collections.Hashtable>
        Key-value pairs in the form of a hash table. For example: @{key0="value0";key1=$null;key2="value2"}
 
        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?       True (ByPropertyName)
        Accept wildcard characters?  false
 
    -Confirm <System.Management.Automation.SwitchParameter>
        Prompts you for confirmation before running the cmdlet.
 
        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?       False
        Accept wildcard characters?  false
 
    -WhatIf <System.Management.Automation.SwitchParameter>
        Shows what would happen if the cmdlet runs. The cmdlet is not run.
 
        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?       False
        Accept wildcard characters?  false
 
    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
Learn PowerShell Scripting in a Month of Lunches

This is an excerpt from Manning's book Learn PowerShell Scripting in a Month of Lunches.

Although it isn’t required, we recommend installing SQL Server Express (the version that includes the SQL Server Management Studio administrative tools). It’s free, and it’ll let you follow along with the excellent chapter on managing data in PowerShell. As of this writing, you can start downloading at https://www.microsoft.com/en-us/sql-server/sql-server-editions-express; we recommend the With Advanced Services download option, which requires you to join Microsoft’s free Visual Studio Dev Essentials program.

#
# Module manifest for module 'MyModule'
#
# Generated by: User
#
# Generated on: 6/19/2017
#

@{

# Script module or binary module file associated with this manifest.
RootModule = 'MyModule.psm1'

# Version number of this module.
ModuleVersion = '1.0'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = 'ea4d119b-6bcf-4540-a389-67cf7d261726'

# Author of this module
Author = 'User'

# Company or vendor of this module
CompanyName = 'Unknown'

# Copyright statement for this module
Copyright = '(c) 2017 User. All rights reserved.'

# Description of the functionality provided by this module
# Description = ''

# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = ''

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This
 prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this
 module. This prerequisite is valid for the PowerShell Desktop edition
 only.
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to
 importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to
 importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in
 RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module, for best performance, do not use
 wildcards and do not delete the entry, use an empty array if there are
 no functions to export.
FunctionsToExport = '*'

# Cmdlets to export from this module, for best performance, do not use
 wildcards and do not delete the entry, use an empty array if there are
 no cmdlets to export.
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module, for best performance, do not use
 wildcards and do not delete the entry, use an empty array if there are
 no aliases to export.
AliasesToExport = '*'

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in
 RootModule/ModuleToProcess. This may also contain a PSData hashtable
 with additional module metadata used by PowerShell.
PrivateData = @{

    PSData = @{

        # Tags applied to this module. These help with module discovery in
 online galleries.
        # Tags = @()

        # A URL to the license for this module.
        # LicenseUri = ''

        # A URL to the main website for this project.
        # ProjectUri = ''

        # A URL to an icon representing this module.
        # IconUri = ''

        # ReleaseNotes of this module
        # ReleaseNotes = ''

    } # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the
 default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

Our hope is that while working your way through this book, or shortly thereafter, you’ll come up with a wonderful, well-written PowerShell tool that solves an immediate problem. It will be even better if it gets you a big raise. But more than that, we hope you’ll share it with the rest of the PowerShell community. For the last few years, this has been easy to do using the PowerShell Gallery from Microsoft. Right now, it contains more than 3,300 modules and 300 scripts.

Windows PowerShell in Action, Third Edition

This is an excerpt from Manning's book Windows PowerShell in Action, Third Edition.

The PowerShell community was stunned (not too dramatic a word) in August 2016 when Microsoft announced that the core of PowerShell was going to be open source. Not only that, but PowerShell would now be available on Linux and Apple operating systems as well as Windows. Jeffrey Snover had been hinting in presentations at the PowerShell Summit (https://powershell.org/summit/) and other venues for a few years that he’d like to see PowerShell as an open source project, but it wasn’t expected to happen so soon.

PS> $sw = New-PSSession -ComputerName W16DSC01
PS> Get-PSSession

Id Name   ComputerName  ComputerType  State  ConfigurationName
-- ----   ------------  ------------  -----  -----------------
 1 SSH1   Lin01.ma...     RemoteMachine Opened DefaultShell
 2 WinRM2 W16DSC01      RemoteMachine Opened Microsoft.PowerShell

PS> Invoke-Command -Session $sl, $sw `
-ScriptBlock {Get-Process -Name PowerShell}

NPM(K) PM(M) WS(M) CPU(s)   Id   SI ProcessName PSComputerName
------ ----- ----- ------   --   -- ----------- --------------
    27 53.44 62.52   1.22 1740    2 powershell  W16DSC01
     0  0.00  0.02  12.18 5863 5809 powershell  Lin01.manticore.org
     0  0.00  0.02   7.70 7898 7898 powershell  Lin01.manticore.org

Microsoft wasn’t the only company running into issues caused by increased complexity. Most people in the industry were having this problem. This led to the Distributed Management Task Force (dmtf.org), an industry organization, creating a standard for management objects called the Common Information Model (CIM). Microsoft’s original implementation of this standard is called Windows Management Instrumentation (WMI).

PowerShell in Depth, Second Edition

This is an excerpt from Manning's book PowerShell in Depth, Second Edition.

Understand that the folks at Microsoft who write PowerShell don’t write the extensions. They provide some tools and rules for the developers who do create extensions, but their job is to create the core PowerShell stuff. Extensions are made by other product teams: The Exchange team makes the Exchange PowerShell extension, the Active Directory team makes its extension, and so on. If you’re looking at a particular extension and don’t like what you see, blame the product team that produced it, not PowerShell. If you’d like to administer something—maybe Windows Internet Name Service (WINS) Server, for example—and PowerShell has no way to administer it, it’s not the PowerShell team’s fault. Blame the owners of the technology you’re trying to work with, and encourage them to get on board and produce a PowerShell extension for their product.

PS C:\> Get-PSSession

 Id Name            ComputerName    State         ConfigurationName    Ava
                                                                       ila
                                                                       bil
                                                                       ity
 -- ----            ------------    -----         -----------------    ---
  6 Session6        win8            Opened        Microsoft.PowerShell ble
  7 Session7        win8            Opened        Microsoft.PowerShell ble

So, the properties and methods—collectively, the members—of a type are defined in the Framework and carried up through PowerShell to you. You can visit http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx to see Microsoft’s .NET Framework documentation for a service, and you’ll see its properties, methods, and so on.

Technically, DefaultDisplayPropertySet is a kind of extension called a PropertySet. You can create other PropertySet extensions apart from a DefaultDisplayPropertySet. Practically speaking, there’s little reason to do so. Microsoft originally had plans for other kinds of PropertySet extensions, but those were never implemented.

PowerShell Deep Dives

This is an excerpt from Manning's book PowerShell Deep Dives.

Don Jones is a senior partner and principal technologist for Concentrated Tech (ConcentratedTech.com). He’s authored and co-authored six books on Windows PowerShell, including Learn Windows PowerShell 3 in a Month of Lunches, Learn PowerShell Toolmaking in a Month of Lunches, and PowerShell in Depth. Don is a Microsoft MVP Award recipient and writes the monthly Windows PowerShell column for Microsoft’s TechNet Magazine (TechNetMagazine.com). Don is also the co-founder and CEO for PowerShell.org, where you’ll find him answering questions in the “General Q&A” and “Remoting” discussion forums.

As you develop your code you’ll continue the process of adding or removing files from change tracking, and when you make significant changes you’ll regularly commit them back to the repository. Once you’ve reached a certain point you may be ready to share your code with others. In this case you can push or pull your code to or from a remote repository. Thanks to Mercurial’s decentralized nature you aren’t forced to synchronize with any central repository unless all of the developers on a project agree to it at the beginning of the project. This means you can push/pull code changes with any replica of your repository. If you’re working on an open source project you might synchronize your local repository with a hosted service, such as Microsoft’s CodePlex open source website Bitbucket.org, or any other source code hosting provider who supports Mercurial repositories.

PS C:\>invoke-psake .\listing_2.ps1
psake version 4.2.0
Copyright (c) 2010 James Kovacs

Executing Build
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.296]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 1/21/2013 3:52:04 PM.
Done Building Project "C:\MyProject\MyProject.csproj" (Build target(s)).

    Build succeeded.
    0 Warning(s)    0 Error(s)
Time Elapsed 00:00:00.21

Build Succeeded!

----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name   Duration
----   --------
Build  00:00:00.2593068
Total: 00:00:00.2713013
PowerShell in Practice

This is an excerpt from Manning's book PowerShell in Practice.

Microsoft seems to be always talking about PowerShell. Listen to a talk about Exchange Server 2007 or 2010, Windows Server 2008 R2 (release 2), or even SQL Server 2008, and PowerShell will be mentioned. PowerShell gets its own section on the Microsoft scripting center and there is a stack of books on the subject. So what’s PowerShell and why are so many people excited about it? This chapter introduces PowerShell and answers some of those basic questions. It is formally known as Microsoft Windows PowerShell but that is too much of a mouthful so we will refer to it as PowerShell from now on. In this chapter you’ll discover:

PowerShell is .NET-based and gives us a way to access to nearly the whole of .NET. This may seem to be of more benefit to programmers than administrators. It’d be easy to think that PowerShell is a programming language rather than an administration tool, given some of the PowerShell examples on the internet. Just because you can write Windows Forms applications in PowerShell doesn’t mean you should! There’s a lot of useful functionality in managed code for the PowerShell administrator, for instance access to SMO to administer SQL Server (see chapter 14) and the interface to IIS 7 (see chapter 13). Microsoft keeps adding functionality into .NET, and administrators should to be aware of the basics. After a quick look at the .NET basics, we’ll see how to use .NET code in PowerShell, and look at the issues of using .NET and how to overcome them.

Listing 5.8. Creating a single user by Microsoft cmdlets
New-ADUser -Name "DARWIN Charles" -SamAccountName "CDarwin" ` -GivenName "Charles" -Surname "DARWIN" ` -Path 'ou=england,dc=manticore,dc=org' -DisplayName "DARWIN Charles" ` -AccountPassword $null -CannotChangePassword $false ` -ChangePasswordAtLogon $true -UserPrincipalName "CDarwin@manticore.org" New-ADUser -Name "NEWTON Isaac" -SamAccountName "INewton" ` -GivenName "Isaac" -Surname "NEWTON" ` -Path 'ou=england,dc=manticore,dc=org' -DisplayName "NEWTON Isaac" ` -AccountPassword (Read-Host -AsSecureString "AccountPassword") ` -CannotChangePassword $false -ChangePasswordAtLogon $true ` -UserPrincipalName "INewton@manticore.org" New-ADUser -Name "SORBY Henry" -SamAccountName "HSorby" ` -GivenName "Henry" -Surname "SORBY" ` -Path 'ou=england,dc=manticore,dc=org' -DisplayName "SORBY Henry" ` -AccountPassword (Read-Host -AsSecureString "AccountPassword")` -CannotChangePassword $false -ChangePasswordAtLogon $true ` -UserPrincipalName "HSorby@manticore.org" Enable-ADAccount -Identity HSorby