If you want to search a specific string within lots of files. Below is what you can do. I use this to search string in SSIS packages:
1. open text file and save as ".ps1";
2. write the following code:
$Path = "your file directory"
$Text = "text you want to search"
$PathArray = @()
# This code snippet gets all the files in $Path that end in ".dtsx".
Get-ChildItem $Path -Filter "*.dtsx" |
Where-Object { $_.Attributes -ne "Directory"} |
ForEach-Object {
If (Get-Content $_.FullName | Select-String -Pattern $Text) {
$PathArray += $_.FullName
}
}
Write-Host "Contents of ArrayPath:"
$PathArray | ForEach-Object {$_}
3. Run the code through powershell_ise.exe which is the GUI for you to look at the data.
(usually it is under c:\Windows\System32\WindowsPowerShell\v1.0\)
Tuesday, April 30, 2019
Monday, April 29, 2019
SQL - to search for specific string used in views or sp
Sometimes after you defined something in your table, e.g. to assigned "Unknown" to a value which is not found from the source. Later, you decide to change "Unknown" to "Undetermined". Then you need to change all places that use that values. Then the following scripts may speed up your modification:
SELECT [Scehma]=schema_name(o.schema_id), o.Name, o.type
FROM sys.sql_modules m
INNER JOIN sys.objects o
ON o.object_id = m.object_id
WHERE m.definition like '%Unknown%' or m.definition like '%Unassigned%'
SELECT [Scehma]=schema_name(o.schema_id), o.Name, o.type
FROM sys.sql_modules m
INNER JOIN sys.objects o
ON o.object_id = m.object_id
WHERE m.definition like '%Unknown%' or m.definition like '%Unassigned%'
Subscribe to:
Posts (Atom)