Sending powershell output to sql server table

Occasional Visitor

I am new to powershell. Please help me. Currently, I am using the below code to send output to sql server table. 

Function CleanUp-PSDrive {
    Get-PSDrive -PSProvider FileSystem | Where { $_.Name -in (69..90 | ForEach-Object { [char]$_ })} | Remove-PSDrive
}$Csv = Import-Csv "path"   

$Csv.Name | ForEach-Object -Begin { $Letter = 69 } {

 new-PSDrive -Root  $_ -Name([char]$Letter) -PSProvider FileSystem -Persist 
 
   if ($Letter -lt 90) 
    { 
      $Letter++ 
    } 
    else 
    { 
        CleanUp-PSDrive        $Letter = 69
    }
} -End { CleanUp-PSDrive } | 
  Select-Object  @{name="File Share Name";expression={$_.'DisplayRoot'}}, @{name="Total(GB)";expression={[math]::Round(($_.free+$_.used)/1GB,2)}}, @{name="Used(GB)";expression={[math]::Round($_.used/1GB,2)}}, @{name="Free(GB)";expression={[math]::Round($_.free/1GB,2)}}, @{name="Total(%)";expression={[math]::Round($_.used/($_.used+$_.free)*100,2)}}, @{name="Date";expression={(Get-Date).ToString('MM-dd-yyyy')}} | 
  
  Write-SqlTableData -serverinstance "usalbsqldev002.logon.ds.ge.com\dev002" -DatabaseName "FileShare" -SchemaName "dbo" -TableName "New1" -force


 

 

0 Replies