Matt Bloomfield

Forum Replies Created

Viewing 15 posts - 16 through 30 (of 429 total)
  • Author
    Posts
  • in reply to: Replace last octet of IP addresses? #283288
    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    When working with IPs like that, I usually just use a ‘\d+$’ to replace the last octet.

    For your desired output:

     

    in reply to: Path Chose manually with a File Browser #282565
    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    Welcome to the forum.  Here’s a basic example.

    The OpenFileDialog class several options, so check the Microsoft documentation for more details such as using multi-select and setting an initial directory.

    in reply to: Has Invoke-RestMethod changed in v7.x? #282529
    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    It’s not Invoke-RestMethod that’s changed but ConvertFrom-JSON.  From version 6, it attempts to convert strings formatted as timestamps to DateTime values.  This causes the UTC information to be lost.

    PowerShell 5.1
    PS E:\Temp> {‘2020-12-27T11:15:00.246+05:30’} | ConvertFrom-Json

    2020-12-27T11:15:00.246+05:30

    PowerShell 7.2
    PS E:\Temp> {‘2020-12-27T11:15:00.246+05:30’} | ConvertFrom-Json

    27 December 2020 05:45:00

    There is an open feature request to add a -DateKind parameter to ConvertFrom-JSON.

    https://github.com/PowerShell/PowerShell/issues/13598

    in reply to: Translate CURL command-line to Powershell #282056
    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    The Invoke-RestMethod equivalent of curl’s -d is the body parameter.  I think the equivalent will be this but obviously I can’t check it works:

    Good reference guide here:

    Curl vs. PowerShell: Comparing Use Cases

    • This reply was modified 1 month ago by Matt Bloomfield. Reason: Formatting
    in reply to: Trying to match a blank column in CSV with regex #281636
    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    \s+ matches 1 or more whitespace characters but you have an empty cell, not a cell with whitespace characters.  Try using ^$ to match an empty string.

    • This reply was modified 1 month ago by Matt Bloomfield. Reason: Corrected Typo
    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    Hi Orlando,

    I doubt you’ll get a reply from that user.  I have reported all the account’s replies but they haven’t been removed yet; it’s just copying and pasting content from blogs that appears to be semi-relevant to the questions being asked, probably in an effort to get some ‘reputation’ so it can continue to spam the link it included in at least one other post.

    If you found its comment useful, here is the full blog article that it stole the content from:

    https://powershellexplained.com/2017-04-22-Powershell-installing-remote-software/

    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    You can get the driver version more efficiently by using a WMI Filter.  At the moment, you’re getting all of the drivers and then filtering them with Where-Object.

    By declaring the [System.Version] type you get objects that are easy to compare

    So then it’s just a case of doing the comparison:

    • This reply was modified 1 month, 1 week ago by Matt Bloomfield. Reason: Formatting
    • This reply was modified 1 month, 1 week ago by Matt Bloomfield. Reason: Formatting Again
    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    Are you saying you just want a list of the KB numbers that appear in the Message field?

     

    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    That modification worked OK for me and matched your desired output.

    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    Andy, I just posted example code which should point you in the right direction but it’s been lost to the spam filter.  I have requested it be released so please check back for it.

    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    It’s not too bad.  Here’s how I modified it to get it working for your use case.

    What I did was build an array using the strings I want to filter against.  Admittedly, this is a much smaller list than yours and I’m not sure how well it will scale, but you could split it into multiple queries.

    Relevant lines 42 & 43:

    $filters = Get-Content E:\temp\files\countries.txt
    $q = $filters -join “‘, ‘”
    This makes an array of strings to use in the query that looks like this
    country1, ‘country2’, ‘country3’, ‘country4 – the outer quotes, which are missing, are added in the query itself.

    I then ran a select on all rows where $q does not appear in the countries column (this is referenced as F2) – I couldn’t get column names working so I stuck with the default provided by OleDB.

    Relevant line 46:

    $sql = “SELECT * FROM [$tablename] WHERE F2 NOT IN (‘$q’) “
    Once finished, the filtered data is in the datatable referenced by $dt so you can just export it as normal.
    $dt | Export-CSV E:\Temp\Files\FilteredData.csv -NoTypeInformation
    Now, as I said, my filter list was much smaller than yours, but the data file was 25MB (I made a subset of the example file previously posted).   It took just 12.9 seconds to get 47000 rows (from 200,000) into $dt.
    My modified script is below.  Full credit for this goes to Chrissy LeMaire, my edits are no more than tinkering.
    Note: I can’t get VS Code to use the x86 shell so run this in the ISE or terminal.

     

    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    There is an inbetween method that might work for you that doesn’t involve SQL (as a server) but does use OleDB that might be worth investigating as you’re using CSV files.

    Chrissy LeMaire (founder of dbatools) has some good articles on handling large CSV files.

    This script is probably good a starting point for what you’re trying to do (in theory, it’s just a case of modifying the query on line 43 🙂 )

    https://blog.netnerds.net/2015/01/quickly-find-duplicates-from-csv-using-powershell/

    I just ran a test using the 2 million sales records file here:

    Downloads 18 – Sample CSV Files / Data Sets for Testing (till 5 Million Records) – Sales

    which is 2 million rows and 238 MB and it took just under 5 minutes to find the >385000 duplicate rows.

    • This reply was modified 1 month, 1 week ago by Matt Bloomfield. Reason: Typo
    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    Just wondering if you’ve tested the code I posted? Get-Content could be the bottleneck and in both of Logan’s examples, Get-Content is being used. You don’t need to use Get-Content with Select-String and not using it can give a performance increase?

    Just a quick example with a 2.5MB file:

    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    You can just add the order part to the existing part that replaces the request id.

    The users are a bit trickier because you have an inconsistent format.  I would make that consistent first as it makes the find and replace simpler.

     

     

    • This reply was modified 1 month, 1 week ago by Matt Bloomfield. Reason: Tried changing theme for better highlighting
    in reply to: Regex in Powershell, line by line from txt-file? #279213
    Participant
    Topics: 4
    Replies: 429
    Points: 770
    Helping Hand
    Rank: Major Contributor

    The simplest solution, I think, is to use the dictionary. It’s not matching that’s the problem but making sure the replacement value has the same case.

Viewing 15 posts - 16 through 30 (of 429 total)