|
mystes posted:You need to run ShowDialog in a separate thread using Start-Job or something but it's kind of annoying in powershell. Thanks, I'll give it a shot. I don't really have the excess time and bandwidth to develop apps in another language, so I'm kinda at the point where if I can't make something work with the tools I've got, I'm just gonna not bother.
|
# ¿ Mar 22, 2019 17:25 |
|
|
# ¿ May 15, 2024 15:33 |
|
So, every 3 weeks I have to change the passwords on a few hundred test accounts and afterwards, the services running as those accounts have to be changed as well. I wrote a script to go out to the associated servers and change the passwords on the services and it 100% works as-advertised except... the services tend to revert to the old password after reboot. Is there something I'm missing here to make this persistent? code:
|
# ¿ Nov 27, 2019 19:40 |
|
Pile Of Garbage posted:What return value are you getting when the Change method of the Win32_Service WMI class is invoked? Going off the doco your usage looks OK however it's a bit vague as to whether the StartName parameter is always required. In the examples section it shows changing a password by specifying only the StartPassword parameter so maybe try it without the StartName parameter (e.g. $_.change($null,$null,$null,$null,$null,$null, $null, $New_Password, $null, $null, $null))? I'll check what's getting returned when I get back to the office on Friday. I'm using wmi instead of Set-Service because they removed Set-Service's remote capability in v6 and later so you have to get funky with Invoke-Command to do that now.
|
# ¿ Nov 28, 2019 04:54 |
|
sloshmonger posted:Assuming that your AD environment will support it, this is exactly the case for a Managed Service Account, or Group Manage Service Account, was made for, unless you're also using those accounts to log in as or do other manual entries. Yes, these are test accounts that are also logged into manually, and also used to run automated testing. So, they're simultaneously:
|
# ¿ Nov 28, 2019 06:17 |
|
New Yorp New Yorp posted:Have you considered automating the provisioning and configuration of these machines with tools like packer and puppet? Manually rotating passwords is kind of an antiquated approach. I don't get to make that call. The Agency mainframe requirement is password change every 28 days and we have to update AD to stay in sync. It would take a literal Act of Congress to change that, I suspect.
|
# ¿ Nov 28, 2019 08:51 |
|
adaz posted:I really should update the OP with all this, a lot has changed since I started this thread. You could always.... start a new thread.
|
# ¿ Jan 28, 2020 20:55 |
|
CzarChasm posted:Working on a different but related script. I'm sure I'm doing this rear end backwards, but I can't seem to google the correct terms to do what I want. Use a registry key?
|
# ¿ Mar 3, 2020 22:34 |
|
BeastOfExmoor posted:I am running the following if statement to figure out if $Destfilename both exists and also is not equal for $File.Name in a ForEach loop. It works most of the time, but I noticed an issue when the filename(s) contains a '!' character. I'm assuming this is a regex issue, but in all my searching I'm not seeing a way to ignore regex and compare string variables as literal? I do not understand. When you use if($Destfilename), you are only checking to see if the variable exists. If you want to see if the file exists, you should be using Test-Path.
|
# ¿ Mar 23, 2020 06:43 |
|
I tried to mimic what I think your intent is, but don't see any issue.code:
|
# ¿ Mar 23, 2020 06:55 |
|
I'd try making a PSCustomObject:code:
|
# ¿ Mar 25, 2020 21:44 |
|
Pile Of Garbage posted:The response body is just a string so you can then parse and deserialise as required. Can't wait to parse some HTML with regex.
|
# ¿ Aug 8, 2020 06:42 |
|
Pile Of Garbage posted:a sane person Buddy...
|
# ¿ Aug 8, 2020 07:27 |
|
Trying to set something up for an installer and this is bugging the hell out of me. CODE: code:
|
# ¿ Oct 14, 2020 16:34 |
|
LegoMan posted:I've been tasked with writing a script (that I already wrote in C but corporate security rules required us to shift to Powershell, don't ask) that removes the tedium of renaming a large number of files after a work activity. Lot of questions here:
An example here does what you are asking, but doesn't make an effort to do that style of string replacement, it just decides the ending format is going to be "ARM##.DAT" and makes files accordingly. If you need something to do actual string replacement (because your filenames may change and you'll need to change the output), let me know and I'll mock that up, too. code:
|
# ¿ Oct 30, 2020 01:47 |
|
Ok, cool. This should have everything, then.code:
|
# ¿ Oct 30, 2020 03:04 |
|
LegoMan posted:
Post your error message. You have done something very wrong.
|
# ¿ Nov 19, 2020 19:08 |
|
LegoMan posted:even better I'll post the function I tried this with just dropping some variables at the bottom and running the function and it worked as-is. I'd need to see your error message to know more. code:
|
# ¿ Nov 19, 2020 22:48 |
|
Try replacing your "break" with a "return(0)" while I try and type something more meaningful up.
|
# ¿ Nov 19, 2020 22:59 |
|
So, my understanding of it, and I'm sure someone with better knowledge will come in and correct all the dumb things I am about to say, is this: Once you start adding the GUI stuff on top, some of the typical PowerShell flow control bits like "break" and "exit" aren't going to work because the GUI wrapper expects a response from each action and bouncing out that way just returns NULL which it doesn't like. So, you have to be careful with your flow control and use return, particularly with a return value, when possible.
|
# ¿ Nov 19, 2020 23:04 |
|
I had to add some fields to the end of a section inside an old-school .INI file today and I wrote this code with equal parts shame and pride:code:
|
# ¿ Dec 30, 2020 16:46 |
|
FISHMANPET posted:Man, you are getting the content of that file way too many times. Definitely, yeah. But it's inconsequential, so I didn't worry about it.
|
# ¿ Dec 30, 2020 17:10 |
|
Why would someone do this?code:
|
# ¿ Feb 23, 2021 20:15 |
|
mystes posted:The last part will remove empty strings. You're splitting each input string on "," flattening the output, and then removing empty strings. Yeah, I mean they literally did that on a line to feed it into a foreach loop instead of: $somelist = ("foo","bar","baz")
|
# ¿ Feb 23, 2021 20:33 |
|
Zaepho posted:Copy Pasta. Probably got some examples from different places to do what they thought they needed to do and just altered it to fit rather than understanding the right way to do it. Yeah, their entire script is full of choice tidbits like this, which is why someone brought it to me to decipher. It'll probably get rubber stamped to go to prod anyway, but at least someone is asking questions.
|
# ¿ Feb 23, 2021 21:01 |
|
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 |
|
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 |
|
nielsm posted:This works for me: Ah, gently caress. I had the drat $newPropertyValue equivalent wrapped in quotes.
|
# ¿ Jun 23, 2021 22:00 |
|
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 |
|
So, this may sound dumb, and that's probably because it is, but uhhh let me kinda describe what I do and what I'm thinking about doing about that, so please give me enough room to hang myself before you bring out the pitchforks. My team's sole focus is deploying install scripts through CM for enterprise deployment and we are like 95%+ PowerShell, with a tiny fraction of MSIs (I've done like 1 or 2 MSIs in my first year). We have 5 people on the team and 1 shared "Standard" library that we include with like... sets up a few variables and logging, and has a handful of poorly documented "common" functions. Otherwise, I'm just sort of left to code each new thing from scratch, in part because this team moved over from WISE Scripting a few years back and a lot of the code from the 1st couple of years of PowerShell has not... aged gracefully. All our applications are stored on a big ol' network share, scripts and payloads and everything, for posterity. I'm free to paw through and use anything I like, but that's largely dependant on having the institutional knowledge to know how each app was done to find stuff for reuse, and again, a lot of the older stuff isn't great. My working theory is to beg a bitbucket setup off the team that manages that (even though it's not really supposed to be used for this), and at least getting all our PS code up into it, so we've got something reasonably searchable so maybe there's a little more standardization and a little less reinventing the wheel. I won't be able to put all the payload files up there, I expect, but maybe I can also export all the applications from CM and throw the XML up there as well (we've really only just started actually exporting and removing old obsolete CM applications, we had ~7 years of Everything Ever Written still clogging up CM before Microsoft put their foot down and told us the servers were keeling over and they weren't going to be able to support our infrastructure if we kept doing that). Does any of this sound logical? I've got a lot of management and team goodwill I can burn, but effectively a $0 budget, and probably a million security restrictions, but I can't see us all just operating our 5 little independent code fiefdoms forever.
|
# ¿ Jun 24, 2021 03:21 |
|
The Fool posted:Get stuff organized into repos ASAP. If your org is already on bitbucket it’s probably fine but Azure devops is free for 5 users and you’ll get some lightweight project management, repos, and pipelines. Thanks. I know like... 1 of those words, but I'll start looking into it. I'm here for the next 20ish years, most likely, so I've got time to grow it. I don't think we're going to get any MS stuff for free, even if only my team of 5 wanted to use it, though. But if I figure out what I'm doing, I can probably get any MS thing eventually, since we've got like a literal billion dollar MS contract.
|
# ¿ Jun 24, 2021 04:05 |
|
Yeah, like today I wanted to stop a service in a script and I was like... I think I remember doing this before but idk which script it was in. So, I had to think it all out and do it all in steps because you can't just "stop a service". It's:
And then do it all in reverse at the end of the script to start the service again. I set myself a reminder to pull that code out and save it in my snippets folder at the end of the week (I've been in PowerBI training all week so, my bandwidth until Friday is limited or I'd do it while it's fresh).
|
# ¿ Jun 24, 2021 04:16 |
|
Zaepho posted:I'm going to address just this bit here. If y'all aren't using https://github.com/PSAppDeployToolkit/PSAppDeployToolkit you should really take a look at it. It may help with a ton of the common library stuff. It also helps encourage building uninstalls alongside the installs. We absolutely are not, and I'll take a look at it, thanks. Part of the problem with moving the group wholesale to any new platform at this point is that we're very beholden to a lot of legacy logging requirements (self-inflicted, not mandated by management), so everything has to log "just so". Unfortunately, each team member does it ~just a little differently~ and even vary it up by script, which is part of why I want to standardize. I figure it's probably a three-step process at this point (for that particular thing): Step 1 is getting all our shared code synched up; Step 2 is to start finding a library system to move to so we aren't writing it ourselves all the time; Step 3 is to migrate our logging to use something compatible with the new system. A good example of a basic problem I'm trying to fix:
I was asked during QC on a script by our senior team member why I had a line at the end of my script that returned a slightly verbose text description with my return code stone point, and I replied that I thought it was good practice to put something in the short, public-facing log that would be informative to the casual observer, and that I was a bit concerned that a lot of them were empty or just a return code. He replied with "I don't know the last time I ever looked at one of those short logs, we just go straight to the verbose ones". I told him that we had 100,000 users and that there were 5 of us, so I thought it was important for the other 99,995 people who would look at a log to have something meaningful, especially if they were reporting a problem to the help desk. He's a pretty good guy, and said he'd look into updating our standard template to have a more standardized default message in the short log, thankfully, but it's very much just one thing on the Big Pile of Cruft That Needs Addressing.
|
# ¿ Jun 24, 2021 15:50 |
|
I mean, I count myself thankful that we do do a bunch of logging, and QC, and testing, and a number of other helpful things, even if we aren't exactly at Best Practices level, yet. And that the team and management are both pretty receptive to change (although preferably incremental). And sometimes the stuff catches me doing stuff that I can do better, even if it's Not Wrong. Like, I had a recent script where I was removing some item properties, and I just wanted them gone, didn't really care if the item had the properties in the first place. So, I just Removed them, and let PS catch the exception. Not So Fast. Even though I was catching the exception and even though it didn't matter that I was trying to remove something that didn't exist, it started bloating up the super verbose transcript log with Informative Error Messages. So, I just added a quick check for existence, and now my logs are clean. I guess it's Technically More Correct this way, even if there's no actual practical difference, but I'd rather get nudged towards being a little more meticulous every now and then, if it also catches me when I Legit gently caress Up.
|
# ¿ Jun 24, 2021 16:14 |
|
FISHMANPET posted:If my "CM" you mean MEMCM (formerly but not actually SCCM) aka ConfigMgr, then you can also log in a format that CMTrace will understand, because odds are good you'll be comfortable with it, and you know it will be there if you're troubleshooting deployments. I will deliver to you the unfortunate news that writing code that returns meaningful data to SCCM/MEMCM/ConfigMgr has at some point been dismissed as an option because "it was just not actually reading the return codes anyway" or something. It's another thing on the pile for me to investigate.
|
# ¿ Jun 24, 2021 16:29 |
|
Hell, yeah, my dudes. Powershell has been added to SA's bbcode: [code=Powershell]PowerShell code:
|
# ¿ Nov 16, 2021 04:35 |
|
lol internet. posted:I made a script to do AD account management (ie. disable, move, clear fields.) I'd start by throwing in Start-Transcript (https://ss64.com/ps/start-transcript.html) at the start of your script and see if that gets you where you need to be. You can invest a lot of time manually catching errors and logging actions, but is it worth it in the long run for this purpose?
|
# ¿ Nov 27, 2021 06:22 |
|
So, I'm trying to introduce the team at work to concepts like "functions" and "not writing things whole cloth every week that are impossible to QC because you aren't reusing code and nobody knows what you are trying to do". And it's an adventure because idk what I'm really doing and so I'm just looking for pointers on how to Best Practice this stuff. The team is fairly receptive to changes I've previously proposed, and they've stated interest in standardizing things going forward, but they've got even less idea what that would look like than I do, and are largely content to just winging it for another decade, unless someone sets the direction for them. So, like, here's an example of one I wrote up this morning. Common piece of code we do is stopping services before an install, but standardizing it into a robust piece with logging so they can just yeet stuff at it and it will Just Work but also make logs, would cut down on time spent and also make it easier to QC. Idk if anyone has any thoughts about whether I'm approaching it the right way, or if there's a better way to handle it. Really open to any suggestions. PowerShell code:
Toshimo fucked around with this message at 00:28 on Jun 9, 2022 |
# ¿ Jun 8, 2022 19:53 |
|
nielsm posted:First, check what's going on with your copy-paste. All the line breaks are double on the forums, and the indentation looks uneven, especially in the documentation block. (Also, 16 spaces indentation is weird too.) Yeah, something went bad copy/pasting it from my email on mobile (also I need to remind the Awful.apk devs that Powershell is a supported language now). nielsm posted:As far as I can tell from reading the code, if you send in services by the pipeline, they're going to be processed sequentially with waiting for the timeout for each individual service. It would run the timeouts in parallel only if you passed the services as an array in a single parameter. Yeah, I wasn't familiar with any of this, so thanks, I'll definitely invest the time into updating my stuff this way, as it'll be a lot more useful. I'm basically working from scratch and I just don't know the things I don't know. nielsm posted:Your return values are odd. This, too. It's very much a "I got things to work by doing this, so this is the way I know to do it". nielsm posted:Consider the standard PowerShell function naming scheme, "Verb-Noun". Stuffing extra terms in front of the verb is bad practice. Yes, I do know this is non-standard, but because I'm working with a group who doesn't have a deep familiarity, I'm prepending everything that is internal with the name of our team so that they can readily identify the inhouse pieces from the standard stuff. nielsm posted:[code=powershell] Thanks for this, I'll see about getting things update in the morning. nielsm posted:The entire way of returning the status seems a little odd to me, but I'm not sure if you intend to connect it with other things on pipeline that want to consume the output. I don't really have a process in place, so no, I wasn't planning on doing other stuff with this. My primary goal is to just start reducing the overhead of a lot of our common stuff to shave off errors and QC time, and then I can revisit it later for better functionality once we've got some breathing room and some more people who know what's up.
|
# ¿ Jun 9, 2022 00:40 |
|
|
# ¿ May 15, 2024 15:33 |
|
Yeah, my shop is weird (or maybe not) because:
It's weird, and not conducive to learning or improvement, but at least it's a bunch of good eggs who are willing to accept new things and improve, so if I can fix me, I can port that stuff over to everyone.
|
# ¿ Jun 9, 2022 02:30 |