I am using powershell code to first connect on a database and from the SELECT I am making, this output is then output :
NAME: %SERVERNAME1
NAME: %SERVERNAME2
Now I want to make a "foreach" loop where it will make a "get-childitem" on every %SERVERNAME to find every EXE files and output to out-gridview.
My foreach look like this but obviously it doesn't work :
$Connection.open()
Write-host "Database Connection $databasename = SUCCESSFULL : Searching role $Role in $palier ..." -foregroundcolor green -backgroundcolor black
$SqlCmd.CommandText = $SqlQuery
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$SqlCmd.Connection = $Connection
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($Dataset)
$Connection.Close()
$Result = $Dataset.Tables[0]
$Result
Foreach ($name in $Result)
{
$name = Get-ChildItem "\\$_\c$\" -recurse -filter *.exe
}
How this foreach could be done ?
P.S. : Didn't want to add to much info since the database connection is working, just want to understand where I am failing on the foreach side.