|
22 Eargesplitten posted:I wrote a 1-liner yesterday that I had some trouble with. Lmao yeah your syntax is all kinds of messed up (Funny how it still works though). This looks a bit nicer: code:
|
# ? Sep 9, 2016 00:40 |
|
|
# ? May 15, 2024 05:14 |
|
GPF posted:Looking at it now, I can see a few places where I could have been more efficient or cut 5 lines down to 2 or less, but this runs at an acceptable speed and, most importantly, does what I need it to do. I like to always put things like your $Servers into a Param block so i can feed the script from anything. $Servers should explicitly be declared as an [array] so that if there is a single item it doesn't get handled wrong. (this is more about bulletproofing for use by others) $myJobs should also explicitly be declared as an [array] "Just In Case" These are really just some quick bulletproofing and "best practice" (yeah yeah, at least what has seemed to keep me out of the most trouble) items. Script looks pretty drat solid and useful. Its a pity that its even necessary though. Seems like purging old failed jobs should be something the print spooler is capable of on it's own.
|
# ? Sep 9, 2016 02:33 |
|
Zaepho posted:Excellent script! A couple of minor critiques. Thanks for the compliments. You're right about what you referenced, but this is currently a script that only I run. When it's just me, I'll tend to make the script a bit 'fragile' so I can make changes quickly depending on the circumstances. When I'm automating or writing stuff for others to use, it's a totally different story. Validate all input! Abort at the first sign of trouble! Be kind, rewind! And, you're right on that last point as well. Why in the hell is the MS print spooler so damned...SQUIRRELY!!??!!?? Why can't HP/Lexmark/Hitachi/Samsung/Canon/Brother/Epson [gently caress Epson in a business situation] actually write drivers that are print server-friendly? GAHH!!
|
# ? Sep 9, 2016 02:53 |
|
mystes posted:Why are you using slashes for parameters? Powershell uses dashes. My only excuse is that I have also been working in the command line. The files are in appdata, but once I gotten into appdata everything is visible. I'll try again with the correct syntax. Since they're all in appdata\local, I'll probably run from Users, and do *\appdata\local for the path. It sounds like force should help when using a dash instead of slash. E: that worked. Strangely enough, I was still getting a bunch of errors, but not for the folders I needed. Now my question is how to find registry keys by value. I've got server entries in the registry, so I want to be able to search for a particular value and replace all instances of that value with the new server name. The Google searches I have done are only bringing up searches for the key name, not the value. 22 Eargesplitten fucked around with this message at 17:11 on Sep 9, 2016 |
# ? Sep 9, 2016 15:58 |
22 Eargesplitten posted:Now my question is how to find registry keys by value. I've got server entries in the registry, so I want to be able to search for a particular value and replace all instances of that value with the new server name. The Google searches I have done are only bringing up searches for the key name, not the value. First, do you actually mean keys, or do you actually mean values? Keep in mind that the registry has this odd structure where the "folders" are called keys, and each key has a number of values. A value has a name, a datatype, and data. The values are the "files". (Historically, there was only one value per key, the one now represented with a blank/null name, shown as (Default) in regedit.) Anyway, first figure out if you're looking for keys, or for key+value name. And whether you're searching by value data or something else. When you use Get-ChildItem in a registry provider tree in PowerShell (e.g. HKLM:\ ) then you only get the keys out as objects, the values are accessed roundabout through the keys. You can do something like this, at least: code:
|
|
# ? Sep 9, 2016 23:18 |
|
I guess I'm looking for the value data then? My lead admin calls the values keys, if I'm understanding you right. He calls the individual items you edit keys. I'm not surprised, though. Everyone here calls display port "Dell DVI" and it drives me crazy. It's 5PM on a Friday, so I'm not quite sure what you're saying at the end there. That stuff you wrote wouldn't find the data (in this case a server name that a program connects to) in a value, right?
|
# ? Sep 10, 2016 00:00 |
22 Eargesplitten posted:I guess I'm looking for the value data then? My lead admin calls the values keys, if I'm understanding you right. He calls the individual items you edit keys. I'm not surprised, though. Everyone here calls display port "Dell DVI" and it drives me crazy. My example searches for keys ("folders") that have a value named "PerceivedType" with a data contents of "video". E.g. for this, it would find the "HKLM:\SOFTWARE\Classes\.MKV" item:
|
|
# ? Sep 10, 2016 00:07 |
|
I think what 22 Eargesplitten wants is a method to return all registry values with a content of "video"?
|
# ? Sep 10, 2016 00:36 |
|
anthonypants posted:I think what 22 Eargesplitten wants is a method to return all registry values with a content of "video"? code:
mystes fucked around with this message at 04:28 on Sep 10, 2016 |
# ? Sep 10, 2016 04:20 |
|
*bursts into thread, panting and out of breath* I THINK You'll find that's more just the registry provider being terrible, not PowerShell itself. Edit: PowerShell is the best because you can do this: code:
Pile Of Garbage fucked around with this message at 14:40 on Sep 13, 2016 |
# ? Sep 13, 2016 14:34 |
|
cheese-cube posted:*bursts into thread, panting and out of breath*
|
# ? Sep 13, 2016 16:22 |
|
I'm trying to automate some IIS site creation to make my job easier / make us look slightly more professional. The thing I'm trying to do at this point is remove a duplicate binding from another site if it exists (this would be behind a -Force parameter, of course). I'm using Get-WebBinding with some filters, but is there a way to pass the -HostHeader parameter so it only returns something with an empty string? If i just omit the parameter or pass it an empty string it just doesn't filter. Example bindings: *:80:site1.local *:80: *:80:site2.local code:
code:
|
# ? Sep 21, 2016 19:51 |
|
I spent way too long trying to use robocopy to move directories source dir looked this \\path\path2\path3\pat*\path4\p* Destination \\path1\path2\path3 Robocopy had issues with the wildcard in the source dir. spent alot time trying to figure it out. in the end all i needed were 3 lines of code Felt pretty stupid afterwards but at least i learned that move-item also moves the child directories and files beneath it. code:
|
# ? Sep 22, 2016 09:27 |
|
Sefal posted:I spent way too long trying to use robocopy to move directories
|
# ? Sep 22, 2016 16:28 |
|
cheese-cube posted:*bursts into thread, panting and out of breath* code:
|
# ? Sep 23, 2016 05:35 |
|
Better yet: add it to their PowerShell profile so that it runs whenever they launch PowerShell.
|
# ? Sep 25, 2016 07:37 |
|
I've been super lazy about keeping the OP updated folks, was going to make a pass at it later today with links to the newer docs, releases, and stuff like the free e-books don jones and co have put out. Anyone else have any recommendations?
|
# ? Sep 25, 2016 20:38 |
|
http://ss64.com/ps/
|
# ? Sep 25, 2016 20:52 |
|
http://powershell.office.com/
|
# ? Sep 25, 2016 20:58 |
|
I want to shoot off a command to our on-prem Exchange and Lync servers as part of our new user script. Right now, I'm using Import-PSSession for each server then running the enable user command, but that seems to have a lot of overhead if I just want to run just the one command. Invoke-Command doesn't seem to be able to use the product-specific commandlets. Is there a better way to run just one Exchange/Lync command remotely?
|
# ? Sep 26, 2016 20:02 |
|
beepsandboops posted:I want to shoot off a command to our on-prem Exchange and Lync servers as part of our new user script.
|
# ? Sep 26, 2016 20:05 |
beepsandboops posted:I want to shoot off a command to our on-prem Exchange and Lync servers as part of our new user script. I can definitely use Invoke-Command to run individual cmdlets on Exchange, without importing the session or making a module from it. I just connect the session with New-PSSession, usually using -Name to set a name for the session so I can easily grab it later with Get-PSSession. (Actually I have a custom Get-ExchangeSession function that tries to get the named session, and if that fails then it establishes one with that name and returns it.) Then just store the session reference into a variable and pass that for -Session on Invoke-Command. I can post an example tomorrow when I'm at work.
|
|
# ? Sep 26, 2016 20:50 |
Basic example of doing Exchange management via Invoke-Command instead of an imported PSSession:code:
|
|
# ? Sep 27, 2016 09:47 |
|
I've started teaching myself powershell this year and so far used it to solve a variety of relatively simple problems - running email traces, querying workstation uptime to see when users are lying about having restarted, and other basic stuff that can be handled in a 10 line script or less. Now I've got a new significant project that will be a massive pain in the rear end to do manually. Naturally I want to automate it, but am not completely sure that what I want to do is reasonably possible via powershell. Basically the problem is that my company's IT department's asset tracking spreadsheet for workstations, laptops and such is woefully out of date. Updating it manually means walking around to hundreds of different machines and plugging in serial numbers and such into an Excel spreadsheet. If I can automate asset creation I can speed up the manual process to only include laptops that don't connect to the domain often. Here's the steps I have envisioned to make this happen. Start off by enabling Powershell remoting on all workstations through Group Policy. - I've already started to roll this out, testing with a single location so far. Then set up scripts to do the following: 1. Iterate through every computer in AD. 2. Filter out the servers and output the names to csv. 3. Create a function that can query a given computer for as much asset sheet info as possible - brand/model/location(based on ip address)/last logged on user/sn/deploy date/etc. 4. Create a script that can run the above function en masse, taking a csv list of names for input and outputting a csv of results. Bonus points if it automatically removes the names of PCs it successfully retrieved info on from the original csv(or creates a new one with failed queries). Does this sound like a reasonable way to go about doing this? I've already figured out steps 1 and 2, but am hitting a brick wall in regards to figuring out the rest.
|
# ? Sep 27, 2016 21:07 |
|
Eschatos posted:I've started teaching myself powershell this year and so far used it to solve a variety of relatively simple problems - running email traces, querying workstation uptime to see when users are lying about having restarted, and other basic stuff that can be handled in a 10 line script or less. Now I've got a new significant project that will be a massive pain in the rear end to do manually. Naturally I want to automate it, but am not completely sure that what I want to do is reasonably possible via powershell. I've pretty much already done 3 & 4 in a script that was supposed to step through all subnet IPs and inventory them. If you can figure out how to get the info from either the registry or WMIC you can easily extract it. It may require PS v5. code:
|
# ? Sep 27, 2016 22:10 |
|
Also, starting with Windows 10, the last boot time is not 100% accurate.
|
# ? Sep 27, 2016 23:55 |
|
Does findstr (or another utility in powershell) let you do relative paths? For instance, I'm in /AncientSourceControl/. Within that are folders with MONTHYEAR. Within those folders is another level, with DB and DEPLOY:code:
Also, Serena Dimensions Space Whale fucked around with this message at 18:51 on Sep 29, 2016 |
# ? Sep 29, 2016 18:48 |
|
Space Whale posted:Does findstr (or another utility in powershell) let you do relative paths? For instance, I'm in /AncientSourceControl/. Within that are folders with MONTHYEAR. Within those folders is another level, with DB and DEPLOY: code:
|
# ? Sep 29, 2016 18:54 |
|
anthonypants posted:dir (yes, and ls) is an alias for Get-ChildItem. Please don't use findstr. You made a mess of your slashes and are confused about what the names of the folders are so I don't know exactly what you're looking for but it should look be something like this: I hit the forward slash since I'm typing this on another computer Can that do internal searches of those file contents - or could I pipe it? Basically I want to find "someString" inside of files ending in .sql where I am where it's currentDirectory\Whatever\DB\theFile.sql and it's in FOO\DB\thefile or BAR\DB\thefile EDIT: The monthyear changes. I want to search for all MONTHYEARS\DB\foo.sql Space Whale fucked around with this message at 19:10 on Sep 29, 2016 |
# ? Sep 29, 2016 18:57 |
|
Space Whale posted:I hit the forward slash since I'm typing this on another computer code:
code:
|
# ? Sep 29, 2016 19:13 |
|
anthonypants posted:You could do either Select-String by itself But how can I search recursively through the folder for any MonthYear\HasTobeDB\*.sql ? Like, can I search for "string" in *\DB\*.sql or .\DB\*.sql?
|
# ? Sep 29, 2016 19:24 |
|
Start at the parent directory and use the -recurse flag?
|
# ? Sep 29, 2016 19:50 |
|
Space Whale posted:But how can I search recursively through the folder for any MonthYear\HasTobeDB\*.sql ? Like, can I search for "string" in *\DB\*.sql or .\DB\*.sql? code:
|
# ? Sep 29, 2016 19:55 |
|
anthonypants posted:If you want to replace a folder name with a wildcard, you can do that. Thank you!
|
# ? Sep 29, 2016 20:06 |
|
How usable is Powershell just as a terminal? I'm way more used to bash, but now that Ubuntu For Windows is a thing I don't have an overwhelming need to constantly frustrate myself by trying to badly fake a GNU/Posix environment on Windows with MSYS+MinGW so I was thinking of moving my command line programming to the msvc toolchains and Powershell as my terminal environment (mostly just opening editors, executing build tools, searching/moving/uzipping files, git, etc). My first impressions are that it's... a bit verbose for that? I like Powershell infinitely more for scripting than bash, in that it's actually readable, and the object model is IMO superior to the "everything is plaintext" philosophy of Unix (even if that has some perks wrt tool compatibility), but even when I know the commands it feels kind of cumbersome. Is it mostly intended for scripting and not extended terminal use? Am I just not used to it and being grumpy?
|
# ? Sep 30, 2016 07:22 |
|
It's an excellent terminal - there are aliases for the most commonly used commands so you aren't always typing Get-ChildItem, Set-Location, Where-Object, and the like. You can also define your own aliases so you can keep using the muscle memory that works for you. The only caveat I've found is that PowerShell doesn't appear to play nice with older interactive command-line tools (cpdr.exe is my chief annoyance, I'm sure there are more). You may have to go back to a Command Prompt to properly use them. The vast majority of my days are spend in PowerShell from beginning to end and it works great.
|
# ? Sep 30, 2016 15:18 |
|
First time trying to use powershell and I have what is probably a simple question: I have a folder on a network drive that has a bunch of .pdf files in a complicated hierarchy of subfolders. I want to copy items from these subfolders to a folder with the same hierarchy on my desktop, but I only want to copy items with a certain list of keywords in the file name. So, for example if I have a folder G:\Docs\2016\9\29\JimBob\ that contains 3 files named Test.pdf, asdf.pdf, and Example.pdf, I want to copy only items that have the word Test or Example in the name. I'm doing some logic so it knows which folders to copy over (new folders are created for each day new files are generated, so I wrote something to loop through the structure and find the most recent stuff). That part is fine and I can recreate the folder structure locally, but I just can't figure out the syntax to copy the actual .pdfs over - whatever I've tried it seems like I get all or nothing. After I've recreated the folder structure, I loop through the final subfolders in the hierarchy (that's what $currentEntity is). $ratesToImport is an array containing the words I want to match in the filenames (so for the above example, I would have Test and Example as items in the array). This is what I'm using: code:
code:
|
# ? Sep 30, 2016 16:37 |
|
Moundgarden posted:And it doesn't seem to actually copy anything over. When I try this: Copy-Item is doing what you told it to, piping no objects out, then Where-Object is doing what you told it to with the no objects that were piped into it. You could try something similar with Get-ChildItem at the first step, then use Where-Object to filter just the objects you want, then pipe that into Foreach-Object and in the script block run Copy-Item on $_. But if you need to match directory structures you'll have to figure something else out. Copy-Item has its own filter switch so you might be able to skip the additional cmdlets entirely. I can't answer you first question, but I do have a suggestion. The last time I looked at doing something fancy with PowerShell to copy directories I ended up just doing it with robocopy.exe. I would rather have done it with PowerShell to learn something but I had a mountain of things to get done. If you want to use robocopy in PowerShell without the shell trying to do a bunch of fancy stuff with your switches start the line with an ampersand, which puts it in what I think was called "command mode."
|
# ? Sep 30, 2016 17:15 |
|
I appreciate the nudge. I managed to get it to work like so:code:
|
# ? Sep 30, 2016 18:39 |
|
|
# ? May 15, 2024 05:14 |
|
Moundgarden posted:It performs like absolute garbage, presumably because of the triple wildcard in the filepath and all the sorting I need to do. I couldn't find a way around that, and unfortunately I have no power to modify the folder structure. Any tips on optimizing something like this or am I pretty much SOL?
|
# ? Oct 1, 2016 02:48 |