Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Pile Of Garbage
May 28, 2007



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.

The hard (?) and stupid part is that the end result should be two .json files that can be textually diffed against each other, to see if the two sources of truth disagree. This means that I need the output normalized, e.g. by writing the keys in a lexicographical order...


Is there a simple way to do that?

If the two JSON files have the same keys and it's only the values that differ then Compare-Object might work.

Adbot
ADBOT LOVES YOU

Xarn
Jun 26, 2015

New Yorp New Yorp posted:

Can't you just sort the two files regardless of syntactic correctness and then compare line by line?

Something like this:
code:
$file1 = @'
{
"hello": "world",
"foo": "bar"
}
'@

$file2 = @'
{
"foo": "bar",
"hello": "world"
}
'@

$file1Lines = ($file1 -split [Environment]::NewLine | sort-object) | % { $_.TrimEnd(',') } 
$file2Lines = ($file2 -split [Environment]::NewLine | sort-object) | % { $_.TrimEnd(',') } 

foreach ($line in $file1Lines) {
    $file2Lines -contains $line
}

That seems like it would break terribly for nested objects, and also is terrifying :v:

I experimented quickly with ordered hashes and I think they will work though.

Xarn
Jun 26, 2015
How do people unit test things in this stupid language?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Xarn posted:

How do people unit test things in this stupid language?

Pester, although it can still be a pain in the rear end.

Xarn
Jun 26, 2015
Thanks. Next question :v:

I wrote this terribleness:
PowerShell code:
<#
.description Takes a dictionary, or list of dictionaries, and returns
them in a canonical order. This means that dictionary's keys are in
lexicographically sorted order, and its values are also recursively
canonicalized.

For arrays the order of their elements is unchanged, but their elements
itself are recursively canonicalized. Things other than arrays and hashes
are unchanged.
#>
function Canonicalize-Dictionary {
    param ($element)
    
    if ($element -IsNot [Array] -And $element -IsNot [Hashtable]) {
        return $element
    }
        
    if ($element -Is [Hashtable]) {
        $newDictionary = [ordered]@{}
        foreach ($key in $element.Keys | Sort-Object) {
            $value = $element[$key]
            $newDictionary[$key] = Canonicalize-Dictionary($value)
        }
        return $newDictionary
    }

    if ($element -Is [Array]) {
        $newArray = @()
        foreach ($key in $element) {
            $newArray += Canonicalize-Dictionary($key)
        }
        return $newArray
    }
    
    Write-Error -Message "Logic error" -ErrorAction Stop
}
I tried some basic testing, and this works

PowerShell code:
> $test1 = @{'1' = 2; '2' = 4}
> Canonicalize-Dictionary($test1)
but this fails with a weird error message about argument being out of range of valid values:
PowerShell code:
> $test2 = @{1 = 2; 2 = 4}
> Canonicalize-Dictionary($test2)
Is this some weird rule with PS trying to be helpful and treating it like a numeric index, instead of string key?? It doesn't really matter to me, because I only need to handle string keys, but still.

Xarn fucked around with this message at 12:58 on Mar 9, 2021

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
I'm not sure if that's going to work for real deserialized JSON since ConvertFrom-Json creates a PSCustomObject, not an associative array.

Xarn
Jun 26, 2015
Yeah, found that out when testing further, there is now a branch that takes PSCustomObject and turns it into a dictionary before recursing. :v:


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 :v:

Toast Museum
Dec 3, 2005

30% Iron Chef

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. :v:


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 :v:

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:
{
    "ID":  87306758,
    "ParentID":  0,
    "Attributes":  [
                       {
                           "ID":  52222,
                           "Order":  0,
                           "Description":  "",
                           "SectionID":  0,
                           "SectionName":  null,
                           "FieldType":  "dropdown",
                           "DataType":  "String"
                       }
                   ]
}
I can see a readability argument for it, but yeah, if it's not what you want, it's a lot of whitespace.

Re: the dumb default depth of 2, you might enjoy $PSDefaultParameterValues

Xarn
Jun 26, 2015

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.
code:
{
    "ID":  87306758,
    "ParentID":  0,
    "Attributes":  [
                       {
                           "ID":  52222,
                           "Order":  0,
                           "Description":  "",
                           "SectionID":  0,
                           "SectionName":  null,
                           "FieldType":  "dropdown",
                           "DataType":  "String"
                       }
                   ]
}
I can see a readability argument for it, but yeah, if it's not what you want, it's a lot of whitespace.

I actually get the opening braces of dicts on the same line, so I have something like this

code:
{
    "okay":  {
                 "long-rear end-key-making-things-bad":  {
                                                        "another-long-rear end-sub-key-making-things-bad":  {
                                                                                ...
}
(this is with PS5)

:suicide:

Toast Museum
Dec 3, 2005

30% Iron Chef

Xarn posted:

I actually get the opening braces of dicts on the same line, so I have something like this

code:
{
    "okay":  {
                 "long-rear end-key-making-things-bad":  {
                                                        "another-long-rear end-sub-key-making-things-bad":  {
                                                                                ...
}
(this is with PS5)

:suicide:

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.

Xarn
Jun 26, 2015
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:
    if ($element -Is [Array]) {
        $newArray = @()
        foreach ($key in $element) {
            $newArray += Canonicalize-Dictionary($key)
        }
        return $newArray
    }
Not really knowing powershell, it took me significant amount of time to figure out why I am losing this array from the representation when there is just one element in it. Having the fix be ,$newArray to create an outer array to guard my array from being decomposed by the return is just :argh:

Xarn fucked around with this message at 22:02 on Mar 10, 2021

Toast Museum
Dec 3, 2005

30% Iron Chef

Xarn posted:

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:
    if ($element -Is [Array]) {
        $newArray = @()
        foreach ($key in $element) {
            $newArray += Canonicalize-Dictionary($key)
        }
        return $newArray
    }
Not really knowing powershell, it took me significant amount of time to figure out why I am losing this array from the representation when there is just one element in it. Having the fix be ,$newArray to create an outer array to guard my array from being decomposed by the return is just :argh:

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.

The Fool
Oct 16, 2003


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.

Xarn
Jun 26, 2015
Oh I know it is intended as a feature, but it caused a real bug in my code :v:

hooah
Feb 6, 2006
WTF?
I'm trying to cobble together a script to use ffmpeg to convert flac files to aiff. So far I have this:
code:
Get-ChildItem -Filter *.flac |
Foreach-Object {
    $newSong = "$_.Basename.aiff"
    [string]$ArgList = '-i "{0}" "{1}"' -f $_, $newSong
    Write-Host -ForegroundColor Green -Object $ArgList

    ffmpeg $ArgList
}
However, something is going wrong when constructing the argument list, and ffmpeg complains:
code:
Unrecognized option 'i 01'.
Error splitting the argument list: Option not found
The printed argument list looks correct, and I can copy & paste it and it works, e.g.
code:
ffmpeg -i "01 - A Christmas Festival Medley.flac" "01 - A Christmas Festival Medley.flac.Basename.aiff"
What's going wrong here?

Toshimo
Aug 23, 2012

He's outta line...

But he's right!
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"

Toshimo
Aug 23, 2012

He's outta line...

But he's right!
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;

hooah
Feb 6, 2006
WTF?

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:

ffmpeg -i $("01 - A Christmas Festival Medley.flac") "01 - A Christmas Festival Medley.flac.Basename.aiff"

I don't know if I did it right (new to PowerShell). I changed the 4th line to
code:
[string]$ArgList = '-i "({0})" "{1}"' -f $_, $newSong
and it has basically the same error:
code:
Unrecognized option 'i (15'.
Error splitting the argument list: Option not found

Toshimo posted:

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;


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

Happiness Commando
Feb 1, 2002
$$ joy at gunpoint $$

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:
PS C:\temp> $foo = get-item .\testfile.txt
PS C:\temp> $foo


    Directory: C:\temp


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         4/17/2021  12:37 PM              0 testfile.txt


PS C:\temp> $foo.basename
testfile
PS C:\temp> "$foo.basename"
C:\temp\testfile.txt.basename
PS C:\temp> "$($foo.basename).suffix"
testfile.suffix
PS C:\temp>

Happiness Commando fucked around with this message at 19:55 on Apr 17, 2021

hooah
Feb 6, 2006
WTF?
This is what ended up working, although I couldn't get the tags to transfer so I just used dBpoweramp instead.
code:
Get-ChildItem -Filter *.flac |
Foreach-Object {
    $newSong = $_.Basename + ".aiff"
    [string]$ArgList = '-i "{0}" -write_id3v2 1 "{1}"' -f $_, $newSong
    Write-Host -ForegroundColor Green -Object $ArgList

    Start-Process -FilePath D:\Programs\ffmpeg-4.2.2-win64-static\bin\ffmpeg.exe $ArgList -Wait -NoNewWindow
}

Hughmoris
Apr 21, 2007
Let's go to the abyss!
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.

Pile Of Garbage
May 28, 2007



Hughmoris posted:

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.

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.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
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?

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Hughmoris posted:

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?

You tried some combination of Get-Printer and Get-PrinterPort?

Hughmoris
Apr 21, 2007
Let's go to the abyss!

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.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

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...

FISHMANPET
Mar 3, 2007

Sweet 'N Sour
Can't
Melt
Steel Beams
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.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

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.

Pile Of Garbage
May 28, 2007



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.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
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

friendbot2000
May 1, 2011

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:
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
Now dbatools has good resources for creating roles and such, and I could do a get, set, test condition statement in regular old powershell, but finding out if the given user has the relevant permissions for the test condition will be a pita so I figured it might be more useful to just create a DSC Resource to do it for me without having to deal with a clunker solution. I am relatively newish to Powershell and DSC but I find I learn better when being presented with a challenge so here I am.

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?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

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:


code:
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
use [Redacted.Redacted]
GRANT INSERT ON SCHEMA :: Redacted TO [techleadrole];  
GRANT UPDATE ON SCHEMA :: Redacted TO [techleadrole];  
GRANT DELETE ON SCHEMA :: Redacted TO [techleadrole];  
go
Now dbatools has good resources for creating roles and such, and I could do a get, set, test condition statement in regular old powershell, but finding out if the given user has the relevant permissions for the test condition will be a pita so I figured it might be more useful to just create a DSC Resource to do it for me without having to deal with a clunker solution. I am relatively newish to Powershell and DSC but I find I learn better when being presented with a challenge so here I am.

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?

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.

friendbot2000
May 1, 2011

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?

I really wanted to like DSC and have tried it a bunch of times, but it's drat near impossible to effectively use.

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

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

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.

friendbot2000
May 1, 2011

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:
function Get-TargetResource
{
	[CmdletBinding()]
	[OutputType([System.Collections.Hashtable])]
	param
	(
		[parameter(Mandatory = $true)]
		[System.String]
		$Account,

		[System.Int16]
		$Port,

        [System.String]
		$IP,
        
        [System.String]
		$Hash
	)

	$getTargetResourceResult = @{
		Account = netsh http show urlacl url=$Account

		Port = netsh http show sslcert ipport=$Port

		IP = netsh http show iplisten
	}

	$getTargetResourceResult
	
}
Is there any reason I cannot execute netsh commands in a hash table? This feels like the most simple solution, which makes me naturally suspicious.

The Fool
Oct 16, 2003


I mean, it works but will create an object array where each element is a line of the text results of the command

Toshimo
Aug 23, 2012

He's outta line...

But he's right!
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?

nielsm
Jun 1, 2009



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:
$newPropertyValue = [byte[]](1,2,3,4,5)
Set-ItemProperty -Path . -Name "test" -Value $newPropertyValue -Type Binary

Toshimo
Aug 23, 2012

He's outta line...

But he's right!

nielsm posted:

This works for me:
code:
$newPropertyValue = [byte[]](1,2,3,4,5)
Set-ItemProperty -Path . -Name "test" -Value $newPropertyValue -Type Binary

Ah, gently caress. I had the drat $newPropertyValue equivalent wrapped in quotes.

Adbot
ADBOT LOVES YOU

Toshimo
Aug 23, 2012

He's outta line...

But he's right!
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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply