Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

For Each - Remove-Item

$
0
0
Hi,The function scripted below executes a stored proc (SP) in SQL. This SP return the database file paths.example:D:\MSSQL11.Test\MSSQL\Data\Test08.mdfD:\MSSQL11.Test\MSSQL\Data\Test08_log.ldfThe SP drops the test db and lists the database file locations. For each row returned I want to delete the file. I know I can do this with Remove-Item $Path but I am not sure how to feed this parameter and run through each file.[code="other"][String] $inventoryinstance="myinstance"[String] $inventorydatabase="DBA_DB"#add-pssnapin sqlserverprovidersnapin100#add-pssnapin sqlservercmdletsnapin100$smoAssembly = [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")if (!($smoVersion)){ Set-Variable -name SmoVersion -value $smoAssembly.GetName().Version.Major -Scope Global -Option Constant -Description "SQLPSX variable" }[reflection.assembly]::LoadWithPartialName('Microsoft.SqlServer.SMOExtended') > $nullfunction Get-ServerList{ $instance = New-Object ('Microsoft.SQLServer.Management.SMO.Server') $inventoryinstance $database = $instance.Databases[$inventorydatabase] $result=$database.ExecuteWithResults("dbo.up_DatabaseFiles_rs") $result.Tables | foreach { $_.Rows} }[/code]

Viewing all articles
Browse latest Browse all 467

Trending Articles