Home » C# ProgrammingRSS

Powershell Script Output to Windows Form List View

Hello,

I have a powerscript see below.

param(
 [ValidateNotNullOrEmpty()]
 [System.String[]] $PackageBasePath
)

# Initialize a hash table that stores GUID -> name associations
$Packages = @{}

# Get a list of all .OSD files below the base path passed in
$SFTFiles = Get-ChildItem $PackageBasePath -filter *.osd -force -recurse

# Store each OSD file's data (name and GUID)
foreach ($SFTFile in $SFTFiles)
{
 # Read the OSD file
 [xml] $SFTFileXML = Get-Content $SFTFile.FullName
 
 # Store relevant information
 $PkgName = $SFTFileXML.SOFTPKG.NAME
 $PkgGUID = $SFTFileXML.SOFTPKG.IMPLEMENTATION.CODEBASE.GUID

 if ($Packages.ContainsKey($PkgGUID) -eq $false)
 {
  $Packages.Add($PkgGUID, $PkgName)
 }
}

Write-Output "`n============================================================`nDependencies found:`n============================================================`n"

# Process each package's dependencies
foreach ($SFTFile in $SFTFiles)
{
 # Read the OSD file
 [xml] $SFTFileXML = Get-Content $SFTFile.FullName
 
 $PkgDependencies = $SFTFileXML.SOFTPKG.IMPLEMENTATION.VIRTUALENV.DEPENDENCIES.CODEBASE
 
 foreach ($PkgDependency in $PkgDependencies)
 {
  # Extract package information (again)
  $PkgName = $SFTFileXML.SOFTPKG.NAME
  $PkgGUID = $SFTFileXML.SOFTPKG.IMPLEMENTATION.CODEBASE.GUID
  
  # Extract the GUID the package depends on
  $PkgDependencyGUID = $PkgDependency.GUID
  
  # Look up the depending package's name
  if ($PkgDependencyGUID -ne $null -and $Packages.ContainsKey($PkgDependencyGUID))
  {
   Write-Output "$PkgName -> $($Packages.Get_Item($PkgDependencyGUID))"
 #           Export-Clixml -path "c:\ps\test.xml" -inputobject "$PkgName -> $($Packages.Get_Item($PkgDependencyGUID))"
         
  }
 }
}

Write-Output "`n============================================================`nAll packages found:`n============================================================"
Write-Output $Packages | format-table -auto @{Label="Name";Expression={$_.Value}},@{Label="GUID";Expression={$_.Name}}

This script will read APP-V OSD files for CODEBASE dependancy and output to screen i.e

Write-Output "$PkgName -> $($Packages.Get_Item($PkgDependencyGUID))"

Now I would like to output this to a windows form control say a listview , please can you advise how I would run the script from C# button and excute the output to a listview control.

Many Thanks Mike.

 

2 Answers Found

 

Answer 1

Create a batch file, add your shell script  to it and execute it from C# . See programing details in the below link. Once your program processed, read  the xml  and add the data  to listview  control.

command execution link:

http://www.123aspx.com/redir.aspx?res=27860

how to read the xml file:

http://support.microsoft.com/kb/307548/en-us

List view  Example:

http://forums.devbuzz.com/m_38710/printable.htm

 

Answer 2

if you got this result please send the code to me how to populate to listview from prowershell result window

send me code to this mail whoknows1984@hotmail.com

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter