Author Posts

June 30, 2016 at 3:49 pm

I what I want to do is that it reads out all the folders from F: \ Test folder and writes it to C: \ temp without which it removes all folders containing al or AL. In the view itself in power shell ISE then shows the right but when it writes so take it with them al and AL

Function GetFileNames([string]$path, [string]$outputFile) {
  $list = Get-ChildItem F:\test
    $list -Replace("al","")
    $list -Replace("AL","")
  $list |  Select-Object Name | Out-File $outputFile
}
GetFileNames ".\" "C:\temp\test.txt"

In the output file i get this:
AL23123
alo2323
 
When it really should get this:
23123
2323

June 30, 2016 at 4:53 pm

You need to use the Replace() method on $list variable rather than assigning a parameter to it (-Replace). And because PowerShell isn't case-sensitive, you only need to use it once:

Function GetFileNames([string]$path, [string]$outputFile) {
  $list = Get-ChildItem F:\test
    $list = $list.Replace("al","") # Will replace any variation of 'al' - 'aL', 'AL', etc.
  $list |  Select-Object Name | Out-File $outputFile
}
GetFileNames ".\" "C:\temp\test.txt"

June 30, 2016 at 4:59 pm

ok its thanks but its posible to

$dataSource = “Server\SQL”
$user = “Admin”
$pwd = “Test”
$database = “Tester”
$connectionString = “Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=False;”

$query = “Select ID from Costomer”

$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
$connection.Open()
$command = $connection.CreateCommand()
$command.CommandText = $query

$result = $command.ExecuteReader()

$table = new-object “System.Data.DataTable”
$table.Load($result)

$table | Format-Table ID -Autosize| Out-File C:\Users\xxxx\Desktop\Db.txt
$connection.Close()

Its that posible to remove ID on top of file

July 5, 2016 at 10:32 am

Its write with AL

July 6, 2016 at 7:54 pm

Hi Vijitharan, You can remove the 'ID' heading on the top of file output by using the -HideTableHeaders SwitchParameter. E.g:

$table | Format-Table ID -Autosize -HideTableHeaders | Out-File C:\Users\xxxx\Desktop\Db.txt