Asked by:
Powershell script text editing

General discussion
-
I have created a script which generates the below mention output.
ServerName ProcessOwner UserName
---------- ------------ --------
ESELNVDA3101 Test\enadsab Test\enadsab
ESELNVDA3102 Test\ERVKLAS Test\ERVKLAS
ESELNVDA3103 Test\ERVKLAS Test\ERVKLAS
ESELNVDA3104 Test\ERVKLAS Test\ERVKLAS
ESELNVDA3105 Test\ERVKLAS Test\ERVKLAS
ESELNVDA3106 Test\ERVKLAS Test\ERVKLAS
ESELNVDA3107 Test\EBBQEUSR Test\EBBQEUSR
ESELNVDA3108 Test\EBBQEUSR Test\EBBQEUSR
ESELNVDA3109 Test\EBBQEUSR Tata\ebceffj Test\EBBQEUSR Tata\ebceffjI want to remove the second user from ProcessOwner Column and from username Column.
Eg:- ESELNVDA3109 Test\EBBQEUSR Tata\ebceffj Test\EBBQEUSR Tata\ebceffj
to
ESELNVDA3109 Test\EBBQEUSR Test\EBBQEUSR
My Script is mention below
Get-BrokerDesktop -MaxRecordCount 30000 | where{$_.desktopkind -like "private"} | Select-Object @{Name='ServerName';Expression={$_.HostedMachineName }} , @{Name='ProcessOwner';Expression={$_.AssociatedUsernames }}, @{Name='UserName';Expression={$_.AssociatedUserNames }} |Out-File C:\test.txt Get-Content C:\test.txt | Foreach-Object {$_ -replace "}", ""} | Set-Content C:\temp\test2.txt Get-Content C:\temp\test2.txt | Foreach-Object {$_ -replace "{", ""} | Set-Content C:\temp\test3.txt Get-Content C:\temp\test3.txt | Foreach-Object {$_ -replace ",", ""} |Set-Content C:\temp\test4.txt Get-Content C:\temp\test4.txt
Kindly help me
Lalit
- Edited by Kumar Lalit Wednesday, November 8, 2017 4:25 PM
Wednesday, November 8, 2017 4:25 PM
All replies
-
If I got you right something like this should be enough:
Get-BrokerDesktop -MaxRecordCount 30000 | Where-Object {$_.desktopkind -like "private" -and $_.AssociatedUsernames -notmatch 'EBBQEUSR' } | Select-Object @{Name='ServerName';Expression={$_.HostedMachineName }} , @{Name='ProcessOwner';Expression={$_.AssociatedUsernames }}, @{Name='UserName';Expression={$_.AssociatedUserNames }} | Out-File C:\test.txt
Best regards (79,108,97,102|%{[char]$_})-join''
Wednesday, November 8, 2017 4:37 PM -
No
I just want only one user and remove everything after the space from ProcessOwner column and and UserName Column.
Eg:- ESELNVDA3109 Test\EBBQEUSR Tata\ebceffj Test\EBBQEUSR Tata\ebceffj to I want output like below. ESELNVDA3109 Test\EBBQEUSR Test\EBBQEUSR
Lalit
- Edited by Kumar Lalit Wednesday, November 8, 2017 4:46 PM
Wednesday, November 8, 2017 4:45 PM -
Split the column on the space and assign the first element back to the column.
$_.ProcessOwner = ($_.ProcessOwner -split ' ')[0]
\_(ツ)_/
Wednesday, November 8, 2017 4:48 PM -
Or
Get-BrokerDesktop -MaxRecordCount 30000 | Where-Object{ $_.desktopkind -like 'private' } | Select-Object @{ n = 'ServerName'; e = { $_.HostedMachineName } }, @{ n = 'ProcessOwner'; e = { ($_.AssociatedUsernames -split ' ')[0] } }, @{ n = 'UserName'; e = { $_.AssociatedUserNames } } | Out-File C:\test.txt
\_(ツ)_/
- Edited by jrv Wednesday, November 8, 2017 5:20 PM
Wednesday, November 8, 2017 4:52 PM -
its not working its giving the below mention output and its completely removed ProcessOwner and UserName Comlumn.
ServerName ---------- ESELNVDA3101 ESELNVDA3102 ESELNVDA3103 ESELNVDA3104 ESELNVDA3105 ESELNVDA3106 ESELNVDA3107 ESELNVDA3108 ESELNVDA3109 ESELNVDA3110 ESELNVDA3111 ESELNVDA3112 ESELNVDA3113 ESELNVDA3114 ESELNVDA3115 ESELNVDA3116 ESELNVDA3118
Lalit
Wednesday, November 8, 2017 5:08 PM -
Your file is not wide enough.
Do this:
Get-BrokerDesktop -MaxRecordCount 30000 | Where-Object{ $_.desktopkind -like 'private' } | Select-Object @{ n = 'ServerName'; e = { $_.HostedMachineName } }, @{ n = 'ProcessOwner'; e = { ($_.AssociatedUsernames -split ' ')[0] } }, @{ n = 'UserName'; e = { $_.AssociatedUserNames } }
\_(ツ)_/
Wednesday, November 8, 2017 5:19 PM -
great Thanks Mate.
It Works
Lalit
Wednesday, November 8, 2017 5:22 PM -
Hey Mate Can you help me with one more thing I need Total Ram of these Servers In one more column. Is it possible to get this.
I was trying something like this
function Get-info { Process { $VDA = Get-BrokerDesktop -MaxRecordCount 30000 | where{$_.desktopkind -like "private"} | Select-Object @{Name='ServerName';Expression={$_.HostedMachineName }} , @{Name='ProcessOwner';Expression={$_.AssociatedUsernames }}, @{Name='UserName';Expression={$_.AssociatedUserNames }} #$Computer = get-wmiobject Win32_computerSystem -ComputerName $vda |select @{Name='TotalRAM';Expression={$_.TotalPhysicalMemory }} foreach ($item in $VDA) { $Prop = [Ordered]@{ 'ServerName' = $item.Servername 'ProcessOwner' = ($item.Processowner ) 'UserName' = $item.Username #'TotalRAM' = "{0:N0}" -f ($item.TotalPhysicalMemory/1GB) } $obj = New-Object -TypeName PSobject -Property $Prop Write-Output $obj } } } Get-info
like
ServerName ProcessOwner UserName Total Ram(KB) ESEKAVDAHP0010 ERICSSON\erickzh ERICSSON\erickzh ESEKAVDAHP0011 ERICSSON\EDBVIT ERICSSON\EDBVIT ESEKAVDAHP0012 ERICSSON\emanrez ERICSSON\emanrez ESEKAVDAHP0013 ERICSSON\eminrin ERICSSON\eminrin ESEKAVDAHP0015 ERICSSON\EDBMAWF ERICSSON\EDBMAWF ESEKAVDAHP0016 ERICSSON\ehuizwu ERICSSON\ehuizwu ESEKAVDAHP0017 ERICSSON\enivpal ERICSSON\enivpal ESEKAVDAHP0018 ERICSSON\evannan ERICSSON\evannan ESEKAVDAHP0019 ERICSSON\ekatmin ERICSSON\ekatmin ESEKAVDAHP0020 ERICSSON\EDBJYAK ERICSSON\EDBJYAK ESEKAVDAHP0023 ERICSSON\xferfab ERICSSON\xferfab ESEKAVDAHP0024 ERICSSON\xedndav ERICSSON\xedndav ESEKAVDAHP0025 ERICSSON\eolezak ERICSSON\eolezak ESEKAVDAHP0026 ERICSSON\xleoand ERICSSON\xleoand ESEKAVDAHP0029 ERICSSON\xbruand ERICSSON\xbruand ESEKAVDAHP0032 ERICSSON\xlidber ERICSSON\xlidber ESEKAVDAHP0033 ERICSSON\xanpatt ERICSSON\xanpatt ESEKAVDAHP0035 ERICSSON\xsamraf ERICSSON\xsamraf ESEKAVDAHP0036 ERICSSON\xflahen ERICSSON\xflahen
Lalit
- Edited by Kumar Lalit Wednesday, November 8, 2017 5:36 PM
Wednesday, November 8, 2017 5:35 PM -
Is it in your file?
Start here:
Learn PowerShell: https://mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276
\_(ツ)_/
Wednesday, November 8, 2017 5:47 PM -
Thanks
Lalit
Wednesday, November 8, 2017 5:52 PM