Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Removing characters from left and right sides from variable.

$
0
0

Hello,

Its script which  gather required information.

$SCCMServerName = 'wx0387.danskenet.net'
$SCCMSiteCode = 'DBP'
$list = get-content 'C:\Users\bb7638\Desktop\list.txt'
foreach ($DPName in $list) {

$pack= Get-WmiObject -ComputerName $SCCMServerName -Namespace root\sms\site_$SCCMSiteCode -Query "SELECT * FROM SMS_PackageStatusDistPointsSummarizer WHERE ServerNALPath like '%$DPName%'" | select packageID, SourceNALPath

}

It returned 2 column value:

packageID SourceNALPath                                                  
--------- -------------                                                  
DB200005  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DB200005\
DBC00384  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC00384\
DBC003CC  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC003CC\
DBC003E7  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC003E7\
DBC003EB  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC003EB\
DBC00407  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC00407\
DBC00711  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC00711\
DBC007B7  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC007B7\
DBC007B8  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC007B8\
DBC007F4  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC007F4\
DBC00811  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC00811\
DBC00820  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC00820\
DBC00822  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC00822\
DBC00827  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC00827\
DBP00003  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBP00003\
DBP0000D  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBP0000D\
DB20021A  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DB20021A\
DB200295  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DB200295\
DBC0003A  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC0003A\
DBC003E8  MSWNET:["SMS_SITE=EEA"]\\WX0809.DANSKENET.NET\SMSPKGE$\DBC003E8\

I would like to remove first 25  character from left and 35 from right. onSourceNALPath  column.

That's should be done as Substring.

For example i made that it should cut from start with code :

($pack.SourceNALPath).substring(0,25)

but its returning output like this ( that i have removed?:

MSWNET:["SMS_SITE=DBP"]\\
MSWNET:["SMS_SITE=DBP"]\\
MSWNET:["SMS_SITE=DBP"]\\
MSWNET:["SMS_SITE=DBP"]\\

Is it possible modify easy in this line below  removing SourceNALPath value first 25 characters and 30 from end:

$pack= Get-WmiObject -ComputerName $SCCMServerName -Namespace root\sms\site_$SCCMSiteCode -Query "SELECT * FROM SMS_PackageStatusDistPointsSummarizer WHERE ServerNALPath like '%$DPName%'" | select packageID, SourceNALPath

If someone have more expierence to understand this logic, please help :)


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>