Powershell search for a word and use the next word

Here is the skinny.  I am trying to easily part through a event log of print jobs.  I export it to a CSV, grab only the events that pertain to what I need but I am stuck there.  Here is a sample of what I need help with.
Microsoft Word - Test Print owned by user1 on computer1 was printed on printer1 through port
Obviously document name, user1, computer1 and printer1 will be different in almost every case.  How do I parse through this and grab the username, computer and printer.  I was thinking search for "owned by", but how do I grab the name?
Thanks for the help.

ok now I am running into another issue.  Apparently the nuances of splitting by word seems to be los on me.
when I do
foreach ($job in $printjob) {        $test = $job.split("owned by")        echo $test}
It will then split the line by each and ever "o", "w", "n", "e", "d", etc.....  I even tried $test = $job.split("'owned by'").  Any ideas?
I feel like I should explain why this is happening.
When you call $job.Split(), you're calling the .NET Split() method of the object System.String.
If you look at the overloads of split (i.e., all the different ways you can call String.Split) - link here https://msdn.microsoft.com/en-us/library/system.string.split%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 -,
you'll notice that the only way of calling String.Split() with a single parameter is if you pass a char[], an array of characters.
Now, if you were coding in C# or VB.NET and you did... String.Split("owned by"), you'd get an error saying that it's expecting a char[] but you gave it a string.
Powershell however is a bit 'smarter' and it tries to accommodate... It knows that the method expects a char[] and it knows you gave it a string, but it also knows how to convert it to a char[], so it does that, and that's what the method String.Split()
receives.
And what happens when the method String.Split() receives a char[]? It splits on every single character in that char[], as you've seen :)
How to fix it? Well, there are two overloads that accept a string[], so you can use those. Now here's an interesting fact...
In the same way that PowerShell converted a string to a char[] to accommodate the needs of the method you were calling, it can also convert a string into a string[], so you could do this:
$job.Split("owned by", [System.StringSplitOptions]::None)
You're passing it a string... and a [StringSplitOptions] object, so you expect it to call the third overload from the page I provided earlier.
But if you run it... you still get the same stuff as before! What gives?
Well, seeing as in this particular case there is an overload that receives char[] and another that receives string[] and you passed a string, which means PowerShell will always have to convert it into something anyway... You have no control
over what PowerShell will decide to convert the string to. It could convert to char[] or to string[]. In this case, because the definition of the char[] method appears before the string[], that gets picked.
So, finally... how to force PowerShell to pick the string[] overload? Well, don't give it a choice!
$job.Split([string[]] "owned by", [System.StringSplitOptions]::None)
So here I'm casting the string into a string[] before it gets passed to the method, so PowerShell does not need to perform any conversion itself and everything is right with the world.
Hope this helps :)

Similar Messages

  • I want to remove the yahoo search bar from Firefox and use the google search bar.

    I did go to about:config and made the keyword.URL to default (Google). It is not getting affected. Please help me to know how can I set it in Firefox.
    I need to remove yahoo search from my Firefox and use the Google search. I did the following steps for the same.
    about:config, searched keyword:URL and reset to default.
    But the change is not getting affected. Pls help

    Work around that I have used (my machine is running Windows XP SP3 might work on other systems as well):
    1) Ensure Firefox is closed, if necessary read this in another browser
    2. Open the Firefox directory on the hard drive (typically: C:\Program Files\Mozilla Firefox)
    3. Go into the 'searchplugins' folder
    4. Delete the file named 'yahoo.xml'
    5. Immediately restart your machine

  • HT4436 can I have a second icloud account for my spouse and use the same apple account

    I was trying to find out if it is possible to set up a second icloud email account for my wife and both use the same apple ID so we can share bought apps without her receiving all of my calander notices, email alerts etc?

    Yes, you can delete your account from settings > iCloud.  Your data will be stored in your personal account (simply choose to delete all information from your iPad when prompted). Then make a new one (again, settings > iCloud) making an account for your class.  When you are done in the classroom, delete the iCloud account again and login with your personal account  When prompted, always delete the information.
    Kind regards,

  • Searching for clip in Premiere using the keywords assigned while ingesting same slip in Prelude...

    Created keywords while ingesting a clip in Prelude , but I can't search for those keywords in premiere and bridge CC... Help!!!

    Gonna need more info.

  • Can you have 2 iTunes accounts, and use the same master card?

    I wonderd if I cold have 2 iTunes accounts, one for me, and one for my mom, and use the same master card on both?
    I dont want my mom to **** up my account if she gets an iPhone. Also she would be using my e-mail and my name.

    Yes.

  • I want to put Acrobat in full screen mode, and use the pencil to write simultaneously.

    I want to put Acrobat in full screen mode for a presentation, and use the pencil to write on the page at the same time. Is there any way both can be used simultaneously?

    George is on the money - you'll not be able to use the pencil tool while in full screen.
    Something to try:
    Use F8 and F9 to hide what is at the top of Acrobat's window.
    Have the Pencil tool selected for use first.
    You'll be able to use the Pencil tool.
    The PDF, with Acrobat's window maximized, will give the appearance of "full screen".
    Be well...

  • I don't have a question so much as a comment for APPLE. I am a new iPhone 5s user and it has many things I like but It is too small and I can only talk on the phone and use the internet if i am in a position to use a wifi connection and that is not good

    I am a new iPhone 5s user. I like many of the features it offers. I don't like that I cannot talk and use the internet (if I am away from WI-FI) and this phone is too small. I am actually thinking of returning it and going back to an Android. After all the hassle it took to get all my stuff working on this phone , it may be worth the switch. This phone needs to be able to multitask freely in this day and age. Also Safari is not the best search engine but I could work with it if I could talk and use it at the same time. I use my phone for business and this is a feature that is needed in my line of work.

    TJBUSMC1973 wrote:
    The iPhone is working, as designed and advertised.  In this case, the user failed to educate themselves properly, either by proper research or asking the right questions, before purchasing the device.
    I understand that the OP failed to do research. But then, I wasn't replying to the OP. I was replying to Chris. I have Verizon. I can talk and use data at the same time with my Droid Maxx. Therefore, the problem is not just with the network. It would be technically possible for an iPhone to do that on Verizon/Sprint if Apple had chosen to use a different chip, such as the kind other phone manufacturers have elected to use.
    Of course, this is probably all irrelevant to the OP's issue. It was merely a point of clarification, especially for those people who are used to being able to use both voice and data at the same time on Verizon. When they switch to an iPhone, they are often surprized at the limitation.
    Best of luck.

  • After upgrading the new operating system, it seems some useful features no longer work such as when typing a message the text anticipates the next word and when trying to delete individual messages from a contact, you can no longer tap and hold to select

    After upgrading the new operating system on my Droid Razr M it seems some useful features no longer work such as when typing a message the text anticipates the next word and when trying to delete individual messages from a contact, you can no longer tap and hold to select multiple message you have to delete them individually or the entire thread. Is there a way to get these back?

    Well, that's kind of embarrassing. And I honestly thought I paid attention to that... It works perfectly now, thank you so much!
    As expected, cdm-git also works fine since DMs only work in the root mode as of now.
    Just for the record, both type commands output "/usr/bin/startx" and pacman -Q gives "systemd 215-4".
    Last edited by looki (2014-08-23 13:04:49)

  • Why does Maverick mail no longer search properly? I used to search for a name and it would find it in All mailboxes. Now it sometimes works, but mostly not. Any solutions?

    Why does Maverick mail no longer search properly?
    I used to search for a name and it would find it in One or All mailboxes. Now it sometimes works, but mostly not. Any solutions?

    I would like to add that Comcast is my internet provider. Perhaps that is part of the issue although the Connection Doctor confirms the mail box is connecting to the internet. No other function processes when Connection Doctor program is used to find the source of the issue. I have read forum posts but am unable to find a way to get my Apple mail to be delivered to my computer. It worked fine up until I chose to transfer mail to the Cloud. My mail account is a .mac account.
    Still hoping someone out there can help me.
    thanks,
    anne

  • How do I set up and use the TV tuner for an ENVY 23 TouchSmart​?

    How do I set up and use the TV tuner for an ENVY 23 TouchSmart?

    Hello LindaLamb:
    First thing is connect your coex TV Anti cable to your computer the end connector looks like a bolt. Then open up Windows Media Center go down the list to live tv and follow and fill in your information with wizard . If your computer doesn't have an built in TV Tunner then you will need to purchase an USB TV tunner. http://www.bing.com/shopping/search?q=usb+tv+tunne​r&qpvt=usb+tv+tunner&FORM=HURE . frrw

  • How to control and use the search criteria values "%" ?

    Hi,
    When I searched some information in my employee name. I filled in search criteria values "%" and selected the "Go" button to see the result. But I got errors that the search criteria values should not begin with a "%" or "_" for at least one if the listed fields.
    How to control and use the search criteria values "%" ?
    Thanks,
    sinolee

    sinolee,
    These kinds of details are mentioned in Dev guide. Always have a look into dev guide before posting.
    --Shiv                                                                                                                                                                                                                                                   

  • I lost my phone and use the IPHone locater, Now that i got my phone back it is disabled and I don't know how to fix it. It had asked for a code but I have no idea what it is so I tried several things but to no avail

    I lost my phone and used the iphone locater to find it. Now that it has been returned to me, it is disabled and says connect to ITUNES. Can you help me ?

    Does the link below help?
    Forgot passcode for your iPhone, iPad, or iPod touch, or your device is disabled - Apple Support

  • Creating a Master virtual hard disk and using the same for all other VM's

    Hi,
    We would like to create a master virtual hard disk and use the same for all other VM's. Can we do that ?
    my requirements :
    1) create 10 VM's
    2) first create a master virtual hard disk with win OS and use the same to create the 10 VM's.
    3) After creating the VM's change the HDD size.
                  -- if i have created master virtual disk with 500GB , and use the same for creating a virtual machine. can we change the HDD size to 1TB ?
    After creating the VM's ,i will change the system names and activate the windows accordingly.
    Will there be any implications ,if we can/will do like this.
    Thanks.

    Hi Suren424,
    I think Using Differencing Disks may cover your needs .
    Please refer to following setps:
       "Create the Parent Virtual Machine Configuration and Virtual Hard Disk
        Install the Operating System, updates, and common software
        Generalize the installation
        Prepare the parent virtual hard disk
        Create the differencing disks
        Create virtual machines that use the differencing disks
    For details please refer to follwing link:
    http://social.technet.microsoft.com/wiki/contents/articles/1393.hyper-v-virtual-machine-vm-parent-child-configuration-using-differencing-disks.aspx
    Hope this helps
    Best Regards
    Elton Ji
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • I have two accounts and for both accounts I use the same emails. I cannot verify my email on my main account because of this. Help? Can I just cancel my other account to avoid confusion?

    I have two accounts and for both accounts I use the same email. I cannot verify my email on my main account because of this. Help? Can I just cancel my other account to avoid confusion? I am totally stuck now.

    By the sounds of it you have linked Email Accounts, if so this means that you will both recieve the majority of the same Emails, and if you do and you read them on your account (which is linked with your husbands) then they will appear to read on the both of them because they are linked. With the majority of Email providers these days they're Emails are (simplified) in the cloud you could say, meaning that if you read or delete shared Emails then it will do the same on both accounts rather than just the yours.
    I hope all that made sense, sorry that I couldn't be of anymore assistance.. If you havent already try googling your problem - you may find some answers on there

  • If I have multiple apple devices and use the same iCloud login on them, shouldn't apple give us more iCloud storage for each device

    If I have multiple apple devices and use the same iCloud login on them, shouldn't apple give us more iCloud storage for each device

    Welcome to Apple Support Communities
    No. Apple only offers 5 GB of free iCloud storage for all your devices, no matter how many you have got. If you need more iCloud storage, purchase storage.

Maybe you are looking for

  • How do I delete a bunch of pictures at the same time?

    How do I delete a bunch of pictures at the same time?

  • BUG-JDev 11G 5407-Project level resource bundle usage messes the page

    When you define a resource bundle on the project properties and if you are using templates the page is not properly rendered in the design view but it runs fine. What happens is , JDev adds a JSTL set tag just before the *<af:pageTemplate>* tag and t

  • IWeb not publishing website via FTP after adding music

    Hi all, When I drag a piece of music on my iWeb website and try to publish via FTP, I get the "there was an error communicating with FTP server" message. Any ideas? Yes this is my own copyrighted music, not other people's music.

  • Customer Fields not extracted by FPBW.

    Hi, dear experts, I have a problem regarding as the extraction of open items via standard transaction FPBW. The fields about the customer information (ex: VKONT and GPART) are not extracted into the table DFKKOPBW. After a search through the OSS note

  • How to keep Ipod in iTunes when undocked

    I want to be able to see and manage my ipod music while it is undocked. I did this before, but for the life of me, can't figure out how to keep the iPod showing in iTunes when it's undocked. Any help would be appreciated. Thanks! Randy Dell   Windows