CmxModule.psm1

<#
 
Installation
    - To install this module, copy the "CmxModule" folder to this directory:
    > [Environment]::GetFolderPath("MyDocuments") + "\WindowsPowerShell\Modules\CmxModule"
    - The module is installed now. You can use it from any powershell console.
 
Use this module
    To use the functions inside this module, load the module into the current
    powershell session:
    > Import-Module CmxModule -Force -DisableNameChecking
    Once loaded, you can now call the module functions. For example to get the version of the
    installed CMX module just call:
    > CmxGetVersion
    To check whether the module is imported into the current powershell session, just call:
    > (Get-Module | Where-Object {$_.Name -eq "CmxModule"}) -ne $null
    To remove the current module from the current powershell session call:
    > Remove-Module CmxModule
 
How to open a PowerShell console where the CMX module is loaded by default
    - Search for PowerShell in the start menu, and open its file location. This is usually:
    %appdata%\Microsoft\Windows\Start Menu\Programs\Windows PowerShell
    - Copy the shortcut "Windows PowerShell" to the same folder.
    - Open the shortcut properties and enter this code into the "Target" field:
    %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoExit -Command "Write-Host 'Load CMX . . .';Import-Module CmxModule -Force -DisableNameChecking; Write-Host Done"
    - Save it. Add this shortcut to the task bar. Whenever you click it, a PowerShell console starts
    and loads the CMX module by default.
 
Function overview
    To see all command of this module, just type:
    > (Get-Command -Module CmxModule).Name
    To see all functions of this module, just type:
    > Get-Command *cmx*
 
Help
    - To get help on a certain command, e.g. CmxGetVersion, just run:
    > Get-Help CmxGetVersion
 
#>



# Includes
. ($PsScriptRoot + "\Scripts\System.ps1")
. ($PsScriptRoot + "\Scripts\String.ps1")
. ($PsScriptRoot + "\Scripts\FileSystem.ps1")
. ($PsScriptRoot + "\Scripts\TFS.ps1")
. ($PsScriptRoot + "\Scripts\VisualStudio.ps1")
. ($PsScriptRoot + "\Scripts\Build.ps1")
. ($PsScriptRoot + "\Scripts\Deploy.ps1")
. ($PsScriptRoot + "\Scripts\RemoteDesktop.ps1")
. ($PsScriptRoot + "\Scripts\DotnetCore.ps1")
. ($PsScriptRoot + "\Scripts\Scripting.ps1")

# Global User variables
[string] $global:WorkspaceName = "Step7_Safety_T"
[string] $global:LocalWorkspace = "D:\WS\Step7_Safety_T"
[string] $global:ServerWorkspace = "$/TIA Portal/TPE/dev/Step7_Safety_T"
[string] $global:BuildDefinition = "TPE.Step7_Safety_T.Rolling"

# Global System variables
[string] $global:ModuleName = "CmxModule"
[string] $global:VsVersion = "[15,16)" 
[string] $global:VsVersion14 = "[14,15)" # VisualStudio 2015
[string] $global:VsVersion15 = "[15,16)" # VisualStudio 2017
[string] $global:VsVersion16 = "[16,17)" # VisualStudio 2019
[string] $global:VsWherePath = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
[string] $global:TfsUrl = "https://jupiter.tfs.siemens.net/tfs/tia"
[string] $global:CmxRootFolder = $PsScriptRoot
[string] $global:BinariesFolder = "$LocalWorkspace\Binaries"

function CmxWriteGlobals()
{
    <#
    .SYNOPSIS
    Writes the CMX global variables to the output.
    #>

    
    Write-Output "VsVersion = $VsVersion"
    Write-Output "VsVersion14 = $VsVersion14"
    Write-Output "VsVersion15 = $VsVersion15"
    Write-Output "VsVersion16 = $VsVersion16"
    Write-Output "VsWherePath = $VsWherePath"
    Write-Output "TfsUrl = $TfsUrl"
    Write-Output "LocalWorkspace = $LocalWorkspace"
    Write-Output "WorkspaceName = $WorkspaceName"
    Write-Output "BuildDefinition = $BuildDefinition"
}

function CmxGetVersion()
{
    <#
    .SYNOPSIS
    Gets the version of the CMX module.
    .EXAMPLE
    $version = Get-CmxVersion
    #>

    
    return (Get-Module -Name $moduleName).Version.ToString()
    # return [System.Version]::new($CmxVersion)
}

function CmxGetRoot()
{
    <#
    .SYNOPSIS
    Gets the root folder of the CMX module e.g. "D:\UserData\z0012stm\Documents\WindowsPowerShell\Modules\CmxModule".
    #>


    return $PsScriptRoot
}

# This call is not available per default.
# To make it available you have to call:
# using module CmxModule
# Then you may use the class.
# Hint: The class must be defined in the "psm1" file.
# Classes in "ps1" files are not loaded when you call:
# using module CmxModule
# The you must call:
# > [CmxInfo]::GetStaticInfo()
# or:
# $obj = New-Object CmxInfo
# $obj.GetInfo()
class CmxInfo
{
    static [string] GetStaticInfo()
    {
        return "Powershell Command Extension Module"
    }

    [string] GetInfo()
    {
        return [CmxInfo]::GetStaticInfo()
    }    
}



function CmxTestFunc1
{
    [CmdletBinding()]
    param()

    # Is shown if $DebugPreference = Continue
    # or this function has argument -Debug
    Write-Debug "A Write-Debug message"

    Write-Host "A Write-Host message 1"
    Write-Host "A Write-Host colored message" -ForegroundColor Blue -BackgroundColor White


    # Is shown if $InformationPreference = Continue
    # or this function has argument -InformationAction Continue
    Write-Information "A Write-Information message"

    # Writes to the ERROR STREAM.
    Write-Error "A Write-Error message" -Category InvalidArgument

    # Is shown if $WarningPreference = Continue or
    # this function has argument -WarningAction Continue
    Write-Warning "A Write-Warning message"

    # Is shown if $VerbosePreference = Continue or
    # this function has argument -Verbose
    Write-Verbose "A Write-Verbose message"

    # Writes to the SUCCESS STREAM.
    # If this function is assigned to a variable or piping elsewhere
    # then this message is not shown in the host.
    Write-Output "A Write-Output message"

    Write-Host "A Write-Host message 2"
}