|
Xarn posted:I have a stupid problem: I have two json documents from different sources, and I want to dump both of them into a text file. That part is easy enough. If the two JSON files have the same keys and it's only the values that differ then Compare-Object might work.
|
# ? Mar 5, 2021 18:01 |
|
|
# ? May 15, 2024 01:34 |
|
New Yorp New Yorp posted:Can't you just sort the two files regardless of syntactic correctness and then compare line by line? That seems like it would break terribly for nested objects, and also is terrifying I experimented quickly with ordered hashes and I think they will work though.
|
# ? Mar 6, 2021 08:03 |
|
How do people unit test things in this stupid language?
|
# ? Mar 8, 2021 18:32 |
|
Xarn posted:How do people unit test things in this stupid language? Pester, although it can still be a pain in the rear end.
|
# ? Mar 8, 2021 19:04 |
|
Thanks. Next question I wrote this terribleness: PowerShell code:
PowerShell code:
PowerShell code:
Xarn fucked around with this message at 12:58 on Mar 9, 2021 |
# ? Mar 9, 2021 12:56 |
|
I'm not sure if that's going to work for real deserialized JSON since ConvertFrom-Json creates a PSCustomObject, not an associative array.
|
# ? Mar 9, 2021 17:21 |
|
Yeah, found that out when testing further, there is now a branch that takes PSCustomObject and turns it into a dictionary before recursing. Then I found out that * ConvertTo-Json adds unholy amounts of whitespace per nesting level (seriously, its like 8 spaces) * The amount of whitespace is actually not deterministic in PS5, which I am stuck in??? (And also that -Depth defaults to stupid low number of 2...) All in all, I am really not enjoying my powershell experience so far
|
# ? Mar 9, 2021 21:33 |
|
Xarn posted:Yeah, found that out when testing further, there is now a branch that takes PSCustomObject and turns it into a dictionary before recursing. I was initially confused by what you said about ConvertTo-Json, because it gives me nice legible four-space indents, but I think I see what you're talking about. Does your Json output contain arrays? It looks like the cmdlet always indents the contents of a block by four spaces relative to the position of the character that opens the block. While opening curly braces go on a new line, opening square brackets are inline, so their contents get indented by however long the previous line was, e.g. code:
Re: the dumb default depth of 2, you might enjoy $PSDefaultParameterValues
|
# ? Mar 9, 2021 23:39 |
|
Toast Museum posted:I was initially confused by what you said about ConvertTo-Json, because it gives me nice legible four-space indents, but I think I see what you're talking about. Does your Json output contain arrays? It looks like the cmdlet always indents the contents of a block by four spaces relative to the position of the character that opens the block. While opening curly braces go on a new line, opening square brackets are inline, so their contents get indented by however long the previous line was, e.g. I actually get the opening braces of dicts on the same line, so I have something like this code:
|
# ? Mar 10, 2021 14:54 |
|
Xarn posted:I actually get the opening braces of dicts on the same line, so I have something like this Weird! My example was generated by 5.1; when you say PS5, do you literally mean 5.0? Alternatively, maybe you've got an old/altered ps1xml file telling it to format Json differently? I'm actually not sure whether a ps1xml file is even involved in this case, but I'm at a loss for what else might be happening.
|
# ? Mar 10, 2021 19:52 |
|
According to $PSVersionTable, I have version 5.1.19041.610 on a freshly provisioned machine. Anyway, found and fixed another bug, I am genuinely beginning to hate powershell, and everyone who had hand in its development. PowerShell code:
Xarn fucked around with this message at 22:02 on Mar 10, 2021 |
# ? Mar 10, 2021 21:56 |
|
Xarn posted:According to $PSVersionTable, I have version 5.1.19041.610 on a freshly provisioned machine. The Json thing is very weird, and I have no idea what might cause that. Does it always do it, or is it only with certain inputs? I know this is usually said as a joke, but that bug you found seems to be intended as a feature. PowerShell tends to assume that you're more interested in the contents than the container, which probably is usually a convenience for the target audience of administrators, but it sure is annoying when the container actually matters.
|
# ? Mar 10, 2021 23:15 |
|
Powershell should only unpack single element (and zero element) arrays in the pipeline. If you pass your array as an argument you shouldn’t have this problem.
|
# ? Mar 10, 2021 23:42 |
|
Oh I know it is intended as a feature, but it caused a real bug in my code
|
# ? Mar 10, 2021 23:46 |
|
I'm trying to cobble together a script to use ffmpeg to convert flac files to aiff. So far I have this:code:
code:
code:
|
# ? Apr 17, 2021 18:37 |
|
ffmpeg does weird poo poo and kinda wants some sort of array option as input sometimes. Idk if that's the solution here, but try changing up your command so that you're sending: ffmpeg -i $("01 - A Christmas Festival Medley.flac") "01 - A Christmas Festival Medley.flac.Basename.aiff"
|
# ? Apr 17, 2021 18:52 |
|
Also, I'd recommend not starting ffmpeg in that fashion. I'd use: Start-Process -FilePath c:\path\to\ffmpeg.exe -ArgumentList $ArgList -Wait -NoNewWindow;
|
# ? Apr 17, 2021 18:58 |
|
Toshimo posted:ffmpeg does weird poo poo and kinda wants some sort of array option as input sometimes. Idk if that's the solution here, but try changing up your command so that you're sending: I don't know if I did it right (new to PowerShell). I changed the 4th line to code:
code:
Toshimo posted:Also, I'd recommend not starting ffmpeg in that fashion. I'd use: Oh hey, this worked (after I removed the parentheses I added in the previous attempt). What is Start-Process doing differently? I spoke a bit too soon. The filenames aren't being constructed quite right: 01 - A Christmas Festival Medley.flac.Basename.aiff hooah fucked around with this message at 19:08 on Apr 17, 2021 |
# ? Apr 17, 2021 19:00 |
|
When you put a variable inside double quotes, it expands the variable first, not including the property (basename, in this case). So when you have "$_.basename.aiff" it's outputting the value of $_ and then appending .basename.aiff to the string. If you want to reference object properties in strings, you have to use the "$($variable.property)" interpolation syntax. This should help:code:
Happiness Commando fucked around with this message at 19:55 on Apr 17, 2021 |
# ? Apr 17, 2021 19:35 |
|
This is what ended up working, although I couldn't get the tags to transfer so I just used dBpoweramp instead.code:
|
# ? Apr 17, 2021 22:51 |
|
I need a little PS help. Often times, but not always, IT will change the printer name but it will keep the same IP address. The application I support needs to work off the printer name, so I'll get a ticket saying "Hey, can you add this printer <name>". I'd like to search by IP address to see if it's the same physical printer but with just a different name. What I need to do: Given a network printer name, how do I find out it's IP address? Or, given an IP address, how do I find the "friendly" name of the printer at that IP address? The friendly name I'm looking for is the same name the user sees if they go into Windows 10 -> Settings -> Printers and Scanners.
|
# ? Apr 23, 2021 20:45 |
|
Hughmoris posted:I need a little PS help. If there is a DNS record for the printer then you can just reference that and you won't need to touch anything as long as the DNS record is kept up-to-date. Also this is very much the wrong thread for this kinda question. IDK what the best thread would be, maybe check whatever is stickied in SH/SC.
|
# ? Apr 23, 2021 21:03 |
|
I added irrelevant details, sorry. In powershell, is there a command to get more info from a network printer if "nslookup <ipaddress>" doesn't return what I need?
|
# ? Apr 23, 2021 21:07 |
|
Hughmoris posted:I added irrelevant details, sorry. You tried some combination of Get-Printer and Get-PrinterPort?
|
# ? Apr 23, 2021 21:15 |
|
Bruegels Fuckbooks posted:You tried some combination of Get-Printer and Get-PrinterPort? I have. From what I can tell, that returns information on printers for the local machine. I'll hop over to the SH/SC printer thread and see if they have any ideas.
|
# ? Apr 23, 2021 21:18 |
|
Hughmoris posted:I have. From what I can tell, that returns information on printers for the local machine. I'll hop over to the SH/SC printer thread and see if they have any ideas. it uses wmi so it can get printers from remote machines as well...
|
# ? Apr 23, 2021 21:31 |
|
Are your clients connecting directly to the printer's IP or connecting to a print queue on a server? I think you've got a process problem, not a technology the problem. There's no standard protocol of "printer names", you can go into the properties of a printer and just set the "name" to whatever. So my guess is that in your environment the printer name means something, and the fact that it can change means there's some kind of process for installing/updating printers on clients, and so you need to look into that business process to get an understanding of what a printer "name" means.
|
# ? Apr 23, 2021 21:32 |
|
Bruegels Fuckbooks posted:it uses wmi so it can get printers from remote machines as well... FISHMANPET posted:Are your clients connecting directly to the printer's IP or connecting to a print queue on a server? I think you've got a process problem, not a technology the problem. There's no standard protocol of "printer names", you can go into the properties of a printer and just set the "name" to whatever. So my guess is that in your environment the printer name means something, and the fact that it can change means there's some kind of process for installing/updating printers on clients, and so you need to look into that business process to get an understanding of what a printer "name" means. Fair enough. I don't know PS or enough details of the network printer setup (I think they are connecting to a print queue on a server) so I'm flailing a bit, was hoping for an easy solution to get around this people/process problem. IT is running the show, I'm just catching the downstream effects when things change and clinicians can't print properly out of the application. I appreciate the help and will work on the process problem.
|
# ? Apr 23, 2021 21:39 |
|
Your job will be a lot simpler if the IT peeps set DNS records for the printers that you could use instead of IPs. Ask them to do that and then to give you the FQDNs of the printers instead of IPs.
|
# ? Apr 23, 2021 21:50 |
|
To wrap this up: since I can't leave well enough alone, I started poking about a bit more. When I ran Get-Printer on my local computer on the VPN, I saw that it had a printer mapped to a network path with a $PrintServerName. I then ran Get-Printer --ComputerName "$PrinterServerName" and that gave a list of printers with their "friendly" name and ports. I then did a little more sleuthing to find the other relevant print server names. A few more checks and I found my target IP and printer. At this point I'll read up on a little more PS, put together a simple script that will poll all of the print servers for their list of printers and then check to see if a given IP is in one of them and what the associated printer name is. The bigger picture is that this is a people/process problem that is outside of my responsibilites but it was a fun puzzle to solve. Thanks for the help everyone
|
# ? Apr 24, 2021 01:02 |
|
I am doing a career pivot to developing DSC Configurations for my company and I am trying for the very first time to make my own DSC Resource because the toolset for dbatools is not great for what I want to do? I am trying to give the techleads at my company database permissions for their respective modules and I want to make a DSC Resource for the following t-sql:code:
Anyways, my first hurdle here is the Mof file and figuring out what I need to use for my target resources and I am a little stumped as to where to start looking for what resources I need to list for this particular job so I uh...was wondering if anyone can give me a couple pointers or places to start?
|
# ? Jun 9, 2021 20:01 |
|
friendbot2000 posted:I am doing a career pivot to developing DSC Configurations for my company and I am trying for the very first time to make my own DSC Resource because the toolset for dbatools is not great for what I want to do? I am trying to give the techleads at my company database permissions for their respective modules and I want to make a DSC Resource for the following t-sql: DSC is a seriously inferior tool when compared to literally anything equivalent (ie chef, ansible, etc). Do you know why DSC was chosen and what else was evaluated? I really wanted to like DSC and have tried it a bunch of times, but it's drat near impossible to effectively use.
|
# ? Jun 9, 2021 20:11 |
|
New Yorp New Yorp posted:DSC is a seriously inferior tool when compared to literally anything equivalent (ie chef, ansible, etc). Do you know why DSC was chosen and what else was evaluated? Well we are a Microsoft shop soooooooooooooo thats basically the reasoning...that and out cybersecurity team makes it nigh impossible to do our jobs as it is so we often have to make do with substandard tools. It was kind of a decision that was already made before I made the switch to being a DBA and now....a weird devops hybrid jack of all trades. I used to work solely in test automation development and .Net dev friendbot2000 fucked around with this message at 20:16 on Jun 9, 2021 |
# ? Jun 9, 2021 20:13 |
|
friendbot2000 posted:Well we are a Microsoft shop soooooooooooooo thats basically the reasoning...that and out cybersecurity team makes it nigh impossible to do our jobs as it is so we often have to make do with substandard tools. Then move as much as possible outside of DSC and clearly delineate what is a "server configuration" activity vs an "application configuration" activity. For example, what you're describing that you want to do with role assignments seems like it's an application configuration activity, so I'd move it outside of DSC entirely and allow the database deployment process for a given application to set whatever roles should be in place. If you're using SSDT for database deployments, that would be the correct place to do this.
|
# ? Jun 9, 2021 20:17 |
|
New Yorp New Yorp posted:Then move as much as possible outside of DSC and clearly delineate what is a "server configuration" activity vs an "application configuration" activity. For example, what you're describing that you want to do with role assignments seems like it's an application configuration activity, so I'd move it outside of DSC entirely and allow the database deployment process for a given application to set whatever roles should be in place. If you're using SSDT for database deployments, that would be the correct place to do this. Well, I will endeavor to push the powers that be in this direction the best I can, I am but a lowly DBA soooooooooooooooo I dont know how successful I can be. I do have a sanity check request for some other code though: code:
|
# ? Jun 21, 2021 19:45 |
|
I mean, it works but will create an object array where each element is a line of the text results of the command
|
# ? Jun 21, 2021 19:57 |
|
Ok, I've been basking my face into this for hours, and I'm trying to do a registry import "the PowerShell way" using New-ItemProperty, and it's all fine and normal until I try to make a Binary value. Then the casting makes it all go to poo poo. I've got something that's originally like "Data"=hex:01,00,02,03 And I've tried pulling it out via PowerShell (I get an array of integers representing the hex values). Trying to just dump that back in with PropertyType Binary and it just silently throws it in as a string type instead. I tried using [byte[]](0x01,0x00,0x02,0x03) and that either does the same (or fails the casting, I don't really recall, I've been through dozens of iterations). Anyone have any idea how to get this translated before I give up and just call the old-school command line?
|
# ? Jun 23, 2021 20:01 |
Toshimo posted:Ok, I've been basking my face into this for hours, and I'm trying to do a registry import "the PowerShell way" using New-ItemProperty, and it's all fine and normal until I try to make a Binary value. This works for me: code:
|
|
# ? Jun 23, 2021 21:16 |
|
nielsm posted:This works for me: Ah, gently caress. I had the drat $newPropertyValue equivalent wrapped in quotes.
|
# ? Jun 23, 2021 22:00 |
|
|
# ? May 15, 2024 01:34 |
|
But, yes, thank you. Just sanity checking me forced me double scrutinize what the hell I was doing because I knew how to do it right and just flubbed the tiniest bit of syntax.
|
# ? Jun 24, 2021 03:06 |