Powershell 只读文件中的节

Powershell 只读文件中的节,powershell,powershell-3.0,Powershell,Powershell 3.0,我想从文件中排除特定内容。例如 我的示例代码: GO CREATE TABLE [dbo].[Employee] ( [EmployeeID] INT NULL, [Name] VARCHAR (50) NULL ); GO CREATE TABLE #tempAP_Data_new ( planeID INT , APNM INT, ) DEC

我想从文件中排除特定内容。例如 我的示例代码:

GO
CREATE TABLE [dbo].[Employee] (
[EmployeeID] INT NULL,
[Name] VARCHAR (50) NULL
);


GO
CREATE TABLE #tempAP_Data_new       (                                                                
planeID INT ,
 APNM   INT,
)

DECLARE             
 @APNM  [VARCHAR] (100) ,   
 @MajorModel [VARCHAR] (100) ,  
 @MinorModel [VARCHAR] (100) ,

CREATE TABLE  #tempnew_Data(                                                                 
planeNum INT ,
APNMID INT,
)
GO
在这里,我只需要
createtable
语句,而不需要
createtable
。输出应为:

CREATE TABLE [dbo].[Employee] (
[EmployeeID] INT NULL,
[Name] VARCHAR(50)NULL
); 
我的代码是:

$searchCreateTable = "CREATE TABLE" 
$alterTable = (Get-Content $path\$deltaFile -Delimiter 'GO') -match  "(?m)^$searchCreateTable*" 

如果语句始终在前5行内,则可以使用
-Head
参数:

Get-Content $path\$deltaFile -Head 5
否则,您可以拆分文件:

(Get-Content $path\$deltaFile -raw) -split 'Go' | select -Index 1

create语句并不总是位于正确的位置。它实际上是一个delta文件。这个逻辑实际上不会工作,因为它不能总是在索引2中