Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

split value of column and write on new line

$
0
0



I have one csv file with different headers and i whant export one colunn for build a new CSV

When my script runs, my export gives me the following example:

DisplayName,BrowserName,Enabled,HideWhenDisabled,Workergroup,Description,AccountDisplayName,AddToClientDesktop,AddToClientStartMenu,WaitOnPrinterCreation,ClientFolder,ApplicationType,ServerNames,CommandLineExecutable,WorkingDir,ContentAddress,ProfileLocation,ProfileProgramName,FolderPath,WindowType,OfflineAccessAllowed,EncodedIconData
IJGC-XenApp 6-5 Desktop,IJGC-XenApp 6-5 Desktop,True,False,,"","LAB\User2,LAB\User3,LAB\User4,LAB\User5",False,False,False,,ServerDesktop,,,,,,,Applications,1024x768,, ,
IJGC - Citrix AppCenter,IJGC - Citrix AppCenter,True,False,,"","LAB\User2,LAB\User3,LAB\User4,LAB\User5",False,False,False,,ServerInstalled,,""C:\Program Files (x86)\Citrix\Citrix Delivery Services Console\Framework\CmiLaunch.exe",C:\Program Files (x86)\Citrix\Citrix Delivery Services Console\Framework,,,,Applications,1024x768,, ,


Is it possible to export only "AccountDisplayName" and build a new csv like this

AccountDisplayName,
LAB\User2,
LAB\User3,
LAB\User4,
LAB\User5,



my script :

 

function XAExport
{
    $LogXAApps = $CSV
   

    ## Create CSV Headers
    log-XenApps "DisplayName,BrowserName,Enabled,HideWhenDisabled,Workergroup,Description,AccountDisplayName,AddToClientDesktop,AddToClientStartMenu,WaitOnPrinterCreation,ClientFolder,ApplicationType,ServerNames,CommandLineExecutable,WorkingDir,ContentAddress,ProfileLocation,ProfileProgramName,FolderPath,WindowType,OfflineAccessAllowed,EncodedIconData"
   
    $XAAppArray = @{}
   
    Write-Host "Exporting XenApp Applications to: " $CSV -ForegroundColor Green
   
    $XAApps = get-xaapplication
   
    foreach($XAApp in $XAApps)
    {
        ## Retrieve CTP v3 cmdlet specific data that is different from XenApp 6 PowerShell SDK
        If ($XA5 -eq $True)
        {   
            $Account = Get-xaaccount -BrowserName $($XAApp.browsername) | Select-Object $_.AccountDisplayName
            $XAIcon = Get-xaapplicationIconStream -BrowserName $($XAApp.browsername) | Select-Object EncodedIconData
            If ($($XAIcon.EncodedIconData.length) -gt "25000")
                {$XenAppIcon = " ,"}
            Else
                {$XenAppIcon = $XAIcon.EncodedIconData}
               
            $Accounts = [string]::join(",",$Account)
            $Accts = '"' + $Accounts + '"'
           
            If (($Servers -eq $True) -and ($WorkerGroups -eq $True))
            {
                If ($($XAApp.ApplicationType) -eq "ServerInstalled" -or $($XAApp.ApplicationType) -eq "StreamedToClientOrInstalled" -or $($XAApp.ApplicationType) -eq "StreamedToServer" -or $($XAApp.ApplicationType) -eq "StreamedToClientOrStreamedToServer" -or $($XAApp.ApplicationType) -eq "ServerDesktop")
                {
                    $XAServerNames = Get-xaserver -BrowserName $($XAApp.browsername) | Select-Object $_.ServerName
                    $XAServer = [string]::join(",",$XAServerNames)
                    $ServerNames = '"' + $XAServer + '"'
                    $WorkerGroup = ""
                }
                Else
                {
                    $ServerNames = ""
                    $WorkerGroup = ""
                }
            }
           
            ElseIf (($WorkerGroups -eq $True) -and ($Servers -eq $False))
            {
                $ServerNames = ""
                $WorkerGroup = ""
            }
               
            ElseIf (($Servers -eq $True) -and ($WorkerGroups -eq $False))
            {
                If ($($XAApp.ApplicationType) -eq "ServerInstalled" -or $($XAApp.ApplicationType) -eq "StreamedToClientOrInstalled" -or $($XAApp.ApplicationType) -eq "StreamedToServer" -or $($XAApp.ApplicationType) -eq "StreamedToClientOrStreamedToServer" -or $($XAApp.ApplicationType) -eq "ServerDesktop")
                {
                    $XAServerNames = Get-xaserver -BrowserName $($XAApp.browsername) | Select-Object $_.ServerName
                    $XAServer = [string]::join(",",$XAServerNames)
                    $ServerNames = '"' + $XAServer + '"'
                    $WorkerGroup = ""
                }
                Else
                {
                    $ServerNames = ""
                    $WorkerGroup = ""
                }
            }   
           
            $AppDescription = '"' + $($XAApp.Description) + '"'
            If ($($XAApp.CommandLineExecutable) -like '"*')
                {
                $XACommandLine = '"' + $($XAApp.CommandLineExecutable) + " " + $($XAApp.CommandLineArguments)
                }
            Else
                {
                $XACommandLine = $($XAApp.CommandLineExecutable) + " " + $($XAApp.CommandLineArguments)
                }

            If ($($XAApp.ContentAddress) -like '"*')
                {
                $XAContent = '"' + $($XAApp.ContentAddress)
                }
            Else
                {
                $XAContent = $($XAApp.ContentAddress)
                }
               
            If ($($XAApp.WorkingDirectory) -like '"*')
                {
                $XAWorkingDir = '"' + $($XAApp.WorkingDirectory)
                }
            Else
                {
                $XAWorkingDir = $($XAApp.WorkingDirectory)
                }
        }
        Else
        {
           
            $Account = Get-xaapplication -BrowserName $($XAApp.browsername) | Get-xaaccount | Select-Object $_.AccountDisplayName
            $XAIcon = Get-xaapplicationIcon -BrowserName $($XAApp.browsername) | Select-Object EncodedIconData
            If ($($XAIcon.EncodedIconData.length) -gt "25000")
                {$XenAppIcon = " ,"}
            Else
                {$XenAppIcon = $XAIcon.EncodedIconData}
               
            $Accounts = [string]::join(",",$Account)
            $Accts = '"' + $Accounts + '"'
           
            If (($Servers -eq $True) -and ($WorkerGroups -eq $True))
            {
                If ($($XAApp.ApplicationType) -eq "ServerInstalled" -or $($XAApp.ApplicationType) -eq "StreamedToClientOrInstalled" -or $($XAApp.ApplicationType) -eq "StreamedToServer" -or $($XAApp.ApplicationType) -eq "StreamedToClientOrStreamedToServer" -or $($XAApp.ApplicationType) -eq "ServerDesktop")
                {
                    $WorkerGroupName = Get-xaapplication -BrowserName $($XAApp.browsername) | Get-xaworkergroup | Select-Object $_.WorkerGroupName
                    $XAServerNames = Get-xaapplication -BrowserName $($XAApp.browsername) | Get-xaserver | Select-Object $_.ServerName
                    $XAServer = [string]::join(",",$XAServerNames)
                    $ServerNames = '"' + $XAServer + '"'
                    $WrkrGrp = [string]::join(",",$WorkerGroupName)
                    $WorkerGroup = '"' + $WrkrGrp + '"'
                }
                Else
                {
                    $ServerNames = ""
                    $WorkerGroup = ""
                }
            }
           
            ElseIf (($WorkerGroups -eq $True) -and ($Servers -eq $False))
            {
                If ($($XAApp.ApplicationType) -eq "ServerInstalled" -or $($XAApp.ApplicationType) -eq "StreamedToClientOrInstalled" -or $($XAApp.ApplicationType) -eq "StreamedToServer" -or $($XAApp.ApplicationType) -eq "StreamedToClientOrStreamedToServer" -or $($XAApp.ApplicationType) -eq "ServerDesktop")
                {
                    $WorkerGroupName = Get-xaapplication -BrowserName $($XAApp.browsername) | Get-xaworkergroup | Select-Object $_.WorkerGroupName
                    $WrkrGrp = [string]::join(",",$WorkerGroupName)
                    $WorkerGroup = '"' + $WrkrGrp + '"'
                    $ServerNames = ""
                }
                Else
                {
                    $ServerNames = ""
                    $WorkerGroup = ""
                }
            }
               
            ElseIf (($Servers -eq $True) -and ($WorkerGroups -eq $False))
            {
                If ($($XAApp.ApplicationType) -eq "ServerInstalled" -or $($XAApp.ApplicationType) -eq "StreamedToClientOrInstalled" -or $($XAApp.ApplicationType) -eq "StreamedToServer" -or $($XAApp.ApplicationType) -eq "StreamedToClientOrStreamedToServer" -or $($XAApp.ApplicationType) -eq "ServerDesktop")
                {
                    $XAServerNames = Get-xaapplication -BrowserName $($XAApp.browsername) | Get-xaserver | Select-Object $_.ServerName
                    $XAServer = [string]::join(",",$XAServerNames)
                    $ServerNames = '"' + $XAServer + '"'
                    $WorkerGroup = ""
                }
                Else
                {
                    $ServerNames = ""
                    $WorkerGroup = ""
                }
            }   
           
            $AppDescription = '"' + $($XAApp.Description) + '"'
            If ($($XAApp.CommandLineExecutable) -like '"*')
                {
                $XACommandLine = '"' + $($XAApp.CommandLineExecutable)
                }
            Else
                {
                $XACommandLine = $($XAApp.CommandLineExecutable)
                }

            If ($($XAApp.ContentAddress) -like '"*')
                {
                $XAContent = '"' + $($XAApp.ContentAddress)
                }
            Else
                {
                $XAContent = $($XAApp.ContentAddress)
                }
               
            If ($($XAApp.WorkingDirectory) -like '"*')
                {
                $XAWorkingDir = '"' + $($XAApp.WorkingDirectory)
                }
            Else
                {
                $XAWorkingDir = $($XAApp.WorkingDirectory)
                }
        }
       
        ## Write data to CSV file
        log-XenApps "$($XAApp.DisplayName),$($XAApp.BrowserName),$($XAApp.Enabled),$($XAApp.HideWhenDisabled),$($WorkerGroup),$($AppDescription),$($Accts),$($XAApp.AddToClientDesktop),$($XAApp.AddToClientStartMenu),$($XAApp.WaitOnPrinterCreation),$($XAApp.ClientFolder),$($XAApp.ApplicationType),$($ServerNames),$($XACommandLine),$($XAWorkingDir),$($XAContent),$($XAApp.ProfileLocation),$($XAApp.ProfileProgramName),$($XAApp.FolderPath),$($XAApp.WindowType),$($XAApp.OfflineAccessAllowed),$($XenAppIcon)"
    }
   
    ## Count Application Type ServerInstalled exported
    $ExportSI = $XAApps | Where-Object {$_.ApplicationType -eq "ServerInstalled"}
    if ($ExportSI.Count -eq $null)
        {$OnlineExp = 0}
    else
        {$OnlineExp = $ExportSI.Count}
   
    ## Count Application Type StreamedToClientOrInstalled exported   
    $ExportSCSI = $XAApps | Where-Object {$_.ApplicationType -eq "StreamedToClientOrInstalled"}
    if ($ExportSCSI.Count -eq $null)
        {$STCOnlineExp = 0}
    else
        {$STCOnlineExp = $ExportSCSI.Count}
   
    ## Count Application Type StreamedToClientOrStreamedToServer exported   
    $ExportSCSS = $XAApps | Where-Object {$_.ApplicationType -eq "StreamedToClientOrStreamedToServer"}
    if ($ExportSCSS.Count -eq $null)
        {$STCSTSExp = 0}
    else
        {$STCSTSExp = $ExportSCSS.Count}
       
    ## Count Application Type StreamedToServer exported   
    $ExportSTS = $XAApps | Where-Object {$_.ApplicationType -eq "StreamedToServer"}
    if ($ExportSTS.Count -eq $null)
        {$STSExp = 0}
    else
        {$STSExp = $ExportSTS.Count}
       
    ## Count Application Type StreamedToClient exported   
    $ExportSTC = $XAApps | Where-Object {$_.ApplicationType -eq "StreamedToClient"}
    if ($ExportSTC.Count -eq $null)
        {$STCExp = 0}
    else
        {$STCExp = $ExportSTC.Count}
       
    ## Count Application Type Content exported   
    $ExportContent = $XAApps | Where-Object {$_.ApplicationType -eq "Content"}
    if ($ExportContent.Count -eq $null)
        {$ContentExp = 0}
    else
        {$ContentExp = $ExportContent.Count}
       
    ## Count Application Type ServerDesktop exported   
    $ExportServerDesktop = $XAApps | Where-Object {$_.ApplicationType -eq "ServerDesktop"}
    if ($ExportServerDesktop.Count -eq $null)
        {$SrvrDesktopExp = 0}
    else
        {$SrvrDesktopExp = $ExportServerDesktop.Count}
   
    ## Add all exported resources for total   
    $ExportAll = $OnlineExp + $ContentExp + $STCOnlineExp + $STCExp + $STSExp + $STCSTSExp + $SrvrDesktopExp
   
    ## Write number of exported resources by type to PowerShell console
    Write-Host "XA Server Installed Apps Exported: " $OnlineExp -ForegroundColor Yellow
    Write-Host "XA Published Content Exported: " $ContentExp -ForegroundColor Yellow
    Write-Host "XA Streamed to client Apps Exported: " $STCExp -ForegroundColor Yellow
    Write-Host "XA Streamed to server Apps Exported: " $STSExp -ForegroundColor Yellow
    Write-Host "XA Server Desktops Exported: " $SrvrDesktopExp -ForegroundColor Yellow
    Write-Host "XA Streamed to client Fallback to XA Server Installed Exported: " $STCOnlineExp -ForegroundColor Yellow
    Write-Host "XA Streamed to client Fallback to XA Streamed to Server Apps Exported: " $STCSTSExp -ForegroundColor Yellow
    Write-Host "XA Apps Exported Total: " $ExportAll -ForegroundColor White
   
}




Many thanks


Viewing all articles
Browse latest Browse all 6937

Trending Articles