user3590915
user3590915

Reputation: 45

Powershell need need assistance select-string command

I am new with powershell and I need some help with command.

Here is my data: I am execute "db2 get dbm cfg" command I am getting below output:

Diagnostic data directory path (DIAGPATH) = c:\users\db2admin\

What I am want to return the value after the = sign, the output should look like this c:\users\db2admin\

Here is the command I running to get the data, but I can’t figure out how to get c:\users\db2admin\

db2 get dbm cfg | select-string -Pattern DIAGPATH|? {-not($_ -match “ALT_DIAGPATH”)}

If ther an option to add to above command to print last value after = sign?

Upvotes: 0

Views: 59

Answers (2)

mjolinor
mjolinor

Reputation: 68243

If that's the only line you get from that command, a simple split should do it:

((db2 get dbm cfg) -split ' = ')[1]

Upvotes: 1

TheMadTechnician
TheMadTechnician

Reputation: 36277

split on = and select the second result (Since the first result will be everything before the =) like this:

((db2 get dbm cfg | select-string -Pattern DIAGPATH|? {-not($_ -match “ALT_DIAGPATH”)}) -split "= ")[1]

Upvotes: 0

Related Questions