<commit_before>﻿<#
.SYNOPSIS 
    This automation runbook stops all Azure virtual machines that are running in a subscription, resource group or single VM.
    If a tag is added to the VM, then only those VMs will be stopped if the TagName parameter is passed in.

.DESCRIPTION
    This automation runbook stops all Azure virtual machines that are running in a subscription, resource group or single VM.
    If a tag is added to the VM, then only those VMs will be stopped if the TagName parameter is passed in.
    This runbook is designed to be run from the Azure automation service.

.PARAMETER VMResourceGroup
    Optional. The name of the resource group the VMs are contained in. If not specified, all VMs in the subscription are stopped.

.PARAMETER VM
    Optional. The name of the VM. If not specified, all VMs in the resource group are stopped.

.PARAMETER TagName
    Optional. The name of the Tag to look for. If specified, only VMs with this tag will be stopped.

.EXAMPLE
    Stop-AzureVM -VMResourceGroup Contoso -VM Marketing

.EXAMPLE
    Stop-AzureVM -VMResourceGroup Contoso -TagName "DevMachines"

.EXAMPLE
    Stop-AzureVM

.NOTES
    AUTHOR: Automation Team
    LASTEDIT: June 12th, 2018
#>
Param
(
    [Parameter(Mandatory=$false)]
    $VMResourceGroupName,

    [Parameter(Mandatory=$false)]
    $VMName,

    [Parameter(Mandatory=$false)]
    $TagName = $null
) 
$RunAsConnection = Get-AutomationConnection -Name "AzureRunAsConnection"

Add-AzureRmAccount `
    -ServicePrincipal `
    -TenantId $RunAsConnection.TenantId `
    -ApplicationId $RunAsConnection.ApplicationId `
    -CertificateThumbprint $RunAsConnection.CertificateThumbprint | Write-Verbose

# Set subscription to work against
$SubscriptionContext = Set-AzureRmContext -SubscriptionId $RunAsConnection.SubscriptionId 

# Script block to stop a VM
$StopVMScriptBlock = {
    Param($VMResourceGroupName, $VMName) 
    Write-Output ("Stopping VM " + $VMName + " in resource group " + $VMResourceGroupName)
    Stop-AzureRmVM -ResourceGroupName $VMResourceGroupName -Name $VMName -Force | Write-Verbose
}

$MAX_JOBS = 50
$VMJobs = @()

# Get all the VMs in the subscription
if  ($VMResourceGroupName -ne $null -and $VMName -ne $null)
{
    $VMs = Get-AzureRMVM -ResourceGroupName $VMResourceGroupName -Name $VMName
}
elseif ($VMResourceGroupName -ne $null)
{
    $VMs = Get-AzureRMVM -ResourceGroupName $VMResourceGroupName
}
else
{
    $VMs = Get-AzureRMVM
}

# Check if VM has the specified tag on it and filter to those.
If ($TagName -ne $null)
{
    $VMs = $VMs | Where-Object {$_.Tags.Keys -eq $TagName}
}

# Start a thread job for each VM
foreach ($VirtualMachine in $VMs)
{
    $VM = Get-AzureRmVM -ResourceGroupName $VirtualMachine.ResourceGroupName -Name $VirtualMachine.Name -Status
    if ($VM.Statuses.Code[1] -eq 'PowerState/running' -and $Tags.Tags.Keys -match $TagNameOnResourceGroup)
    {
        # Process up to MAX_JOBS at a time so as to not overwhelm the host
        $VMJob = Start-ThreadJob -ScriptBlock $StopVMScriptBlock -ArgumentList $VM.ResourceGroupName, $VM.Name -ThrottleLimit $MAX_JOBS
        $VMJobs+=$VMJob
    }
}

# Write out the job status
foreach ($Job in $VMJobs)
{
        Wait-Job -id $Job.Id | Write-Verbose
        if ($Job.Error.Count -gt 0)
        {
            Write-Error -Message $Job.Error.Exception
        }
        else 
        {
            Write-Output $Job.Output[0]
        }
}
<commit_msg>Update Stop-AzureVM.ps1<commit_after>﻿<#
.SYNOPSIS 
    This automation runbook stops all Azure virtual machines that are running in a subscription, resource group or single VM.
    If a tag is added to the VM, then only those VMs will be stopped if the TagName parameter is passed in.

.DESCRIPTION
    This automation runbook stops all Azure virtual machines that are running in a subscription, resource group or single VM.
    If a tag is added to the VM, then only those VMs will be stopped if the TagName parameter is passed in.
    This runbook is designed to be run from the Azure automation service.

.PARAMETER VMResourceGroup
    Optional. The name of the resource group the VMs are contained in. If not specified, all VMs in the subscription are stopped.

.PARAMETER VM
    Optional. The name of the VM. If not specified, all VMs in the resource group are stopped.

.PARAMETER TagName
    Optional. The name of the Tag to look for. If specified, only VMs with this tag will be stopped.

.EXAMPLE
    Stop-AzureVM -VMResourceGroup Contoso -VM Marketing

.EXAMPLE
    Stop-AzureVM -VMResourceGroup Contoso -TagName "DevMachines"

.EXAMPLE
    Stop-AzureVM

.NOTES
    AUTHOR: Automation Team
    LASTEDIT: June 12th, 2018
#>
Param
(
    [Parameter(Mandatory=$false)]
    $VMResourceGroupName,

    [Parameter(Mandatory=$false)]
    $VMName,

    [Parameter(Mandatory=$false)]
    $TagName = $null
) 
$RunAsConnection = Get-AutomationConnection -Name "AzureRunAsConnection"

Add-AzureRmAccount `
    -ServicePrincipal `
    -TenantId $RunAsConnection.TenantId `
    -ApplicationId $RunAsConnection.ApplicationId `
    -CertificateThumbprint $RunAsConnection.CertificateThumbprint | Write-Verbose

# Set subscription to work against
$SubscriptionContext = Set-AzureRmContext -SubscriptionId $RunAsConnection.SubscriptionId 

# Script block to stop a VM
$StopVMScriptBlock = {
    Param($VMResourceGroupName, $VMName) 
    Write-Output ("Stopping VM " + $VMName + " in resource group " + $VMResourceGroupName)
    Stop-AzureRmVM -ResourceGroupName $VMResourceGroupName -Name $VMName -Force | Write-Verbose
}

$MAX_JOBS = 50
$VMJobs = @()

# Get all the VMs in the subscription
if  ($VMResourceGroupName -ne $null -and $VMName -ne $null)
{
    $VMs = Get-AzureRMVM -ResourceGroupName $VMResourceGroupName -Name $VMName
}
elseif ($VMResourceGroupName -ne $null)
{
    $VMs = Get-AzureRMVM -ResourceGroupName $VMResourceGroupName
}
else
{
    $VMs = Get-AzureRMVM
}

# Check if VM has the specified tag on it and filter to those.
If ($TagName -ne $null)
{
    $VMs = $VMs | Where-Object {$_.Tags.Keys -eq $TagName}
}

# Start a thread job for each VM
foreach ($VirtualMachine in $VMs)
{
    $VM = Get-AzureRmVM -ResourceGroupName $VirtualMachine.ResourceGroupName -Name $VirtualMachine.Name -Status
    if ($VM.Statuses.Code[1] -eq 'PowerState/running')
    {
        # Process up to MAX_JOBS at a time so as to not overwhelm the host
        $VMJob = Start-ThreadJob -ScriptBlock $StopVMScriptBlock -ArgumentList $VM.ResourceGroupName, $VM.Name -ThrottleLimit $MAX_JOBS
        $VMJobs+=$VMJob
    }
}

# Write out the job status
foreach ($Job in $VMJobs)
{
        Wait-Job -id $Job.Id | Write-Verbose
        if ($Job.Error.Count -gt 0)
        {
            Write-Error -Message $Job.Error.Exception
        }
        else 
        {
            Write-Output $Job.Output[0]
        }
}

{'fraction_non_alphanumeric': 0.0837727006444054, 'fraction_numerical': 0.003368482718219098, 'mean_word_length': 3.344147582697201, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '490542', 'n_tokens_mistral': 2097, 'n_tokens_neox': 2062, 'n_words': 733}