Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

IT-Wiki

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View my Codeberg Page

View my Photo Website

Collection to String

published: August 2, 2016 author: Tinu tags: String categories: PowerShell


Immer wenn eine Collection in einen String umgewandelt werden soll…

function Convert-CollectionToString
{
    <# Convert System.Collections.Specialized.StringCollection to String #>
    param(
        [Parameter(Mandatory = $true)] $col
    )
    $function = $($MyInvocation.MyCommand.Name)
    [String] $ret = $null
    try
    {
        if($psdebug)
        {
            Write-Verbose -Message "Running $($function) ..." -Verbose
        }
        if($col -is [System.Collections.Specialized.StringCollection])
        {
            foreach($item in $col)
            {
                $ret = "$($ret) $($item)"
            }
        }
        else
        {
            $ret = $col
        }
    }
    catch [Exception]
    {
        if($psdebug)
        {
            Write-Error -Message "$($function): $($_.Exception.Message)" ...
        }
        else
        {
           "$(get-date -f 'yyyy-MM-dd HH:mm:ss') - [   ERROR   ] $($function): $($_.Exception.Message)" | Out-File "$($Global:Logfile)" -Encoding ascii -Append

        }
        $error.clear()
    }
    if($psdebug)
    {
        Write-Verbose -Message "$($function): Return $($ret)" -Verbose
    }
    return $ret
}

← Previous Post ◇ [ Top ] ◇ Copyright © 2024 by tinuwalther ◇ [ Blog ] ◇ Next Post →