|
In PowerShell, how do I loop through a text file and insert "Sleep(500)" in between each line? I have text files that contain AutoIt Recorder code, and I want to pause .5 seconds between each block of code. I know I could learn to do it with AutoIt but I'm curious as to what it would look like in PowerShell. Ithaqua posted:Let's say you're in C:\Foo\Bar\Baz\ I definitely didn't know that. Thank you. Hughmoris fucked around with this message at 18:43 on Jul 25, 2014 |
# ¿ Jul 25, 2014 18:38 |
|
|
# ¿ Apr 29, 2024 04:03 |
|
Ithaqua posted:get-content .\test.txt | % { $_ + [System.Environment]::NewLine +"Sleep(500)" } | set-content .\output.txt Thank you for this. Coming from kicking Python around, that all looks very confusing. But I'm getting its like any language, once you get exposed to it a little bit it all makes sense
|
# ¿ Jul 25, 2014 19:41 |
|
Ithaqua posted:I'll break it down: Thanks for breaking everything down. I've been flipping through the book and I'm thinking my needs will be better suited by AutoIt. I won't be doing much administration tasks but rather testing and the sorts that involve recording mouse movements and keystrokes. I'll definitely keep the book on the shelf though.
|
# ¿ Jul 28, 2014 22:13 |
|
Ithaqua posted:Automated testing? Use an actual testing framework. Coded UI records your actions, translates them to .NET code, and lets you play them back. Then you can integrate it into a build/deploy process, especially if you use MTM for managing test cases. I'm diving headfirst into this new job and am probably not explaining myself correctly. I work in informatics at a hospital and I'm testing software that our nurses use to chart on patients. The software is made by McKesson. For my testing, I essentially open up a form, click/check/radio multiple options (sometimes random), then click SUBMIT. Afterwards I read over it and see if there are any weird errors or issues. AutoIt makes it very simple to record my mouse movement and clicks but it definitely isn't great because each form is different and each selection box may be in a different spot. Is that something I could attack with a different solution?
|
# ¿ Jul 28, 2014 22:46 |
|
Ithaqua posted:I don't understand why you'd be testing a vendor's software. That's the vendor's job. If their poo poo doesn't work right, tell them. We have the ability to build and customize forms based on the framework that the software creator provided us. After creating or customizing a form, we test it in a train environment before sending it out to Live. This is my first job in this capacity so I'm not sure if its the norm or not, especially for healthcare. I don't currently have access to Visual Studio and I think I'd raise a few eyebrows if I asked for it. None of the coworkers in my office automate anything, mainly from lack knowledge I'm guessing. They are open to it though. They really enjoyed seeing how fast AutoIt could complete some of our mundane tasks. wwb posted:Does their software have the windows accessiblity hooks built in? Is it keyboard operable? Sendkeys is fun and easy and the way we used to do this poo poo before we had newfangled crap like coded ui. I'm not sure. I'd get blank looks if I asked anyone I have access to. I'm new, and testing/automating is a small part of my responsibilities so I don't want to come off as overzealous yet. However, poking around it looks like the coding for the iforms we use are in html and javascript. Didn't mean to hijack the powershell thread but I appreciate the inputs. Hughmoris fucked around with this message at 15:50 on Jul 29, 2014 |
# ¿ Jul 29, 2014 15:40 |
|
I need to accomplish a task and I'm thinking powershell might be my only hope. I need to schedule a task on 10 VMs, but I need to have it specific to a second. For example, at 08:40:15 I want to launch notepad.exe on VM1. Then at 08:40:20 I want to launch notepad.exe on VM2. Ideally, I'd like to sit at my workstation and use powershell to schedule the tasks. What I have been doing is using the taskscheduler GUI but its clunky and takes forever to work my way through 10 VMs. I've tried learning more about SCHTASKS in command prompt but you can only schedule by the minute, you can't schedule by the second. All computers will be running Windows 7. Can powershell handle something this or do I need to get more creative? *I was thing maybe I could use the TaskScheduler GUI to create my task which will open notepad at 08:40:15. Then open powershell or command prompt and find that task, then copy it out to the other machines. Not sure if that would work. Hughmoris fucked around with this message at 03:49 on Aug 16, 2014 |
# ¿ Aug 16, 2014 03:43 |
|
Dr. Arbitrary posted:I'm away from my desk but I would start with get-help new-ScheduledTask -full I opened powershell, ran get-help new-ScheduledTask -full and receiver the error code:
I'm not positive what you mean about getting the times. It would run something like this: code:
|
# ¿ Aug 16, 2014 04:01 |
|
Dr. Arbitrary posted:poo poo. I hate when that happens. I'll have to do it without installing any further software. And you're right, while its irritating its also a fun brain puzzler. After googling, I'm thinking maybe create the task on all the machines using the command prompt for 08:00. Then somehow export the task which appears to be an XML, edit the XML to have the time be 08:00:05, then import it. Not sure if I'm going crazy after dealing with this all day.
|
# ¿ Aug 16, 2014 04:39 |
|
Dr. Arbitrary posted:.Net is a prerequisite for powershell so that won't be a problem. At first glance it looks like the site you listed could be a more elegant solution but I'm not too familiar with a lot of the code being used. So, I went about solving it like a caveman. 1. At my workstation, I create a local task in command-prompt: code:
code:
4. I then export that newly adjusted task file to each VM: code:
I tested it on 2 machines and it appears to work. Ugly but effective. I'm definitely ears for other solutions though. Hughmoris fucked around with this message at 05:33 on Aug 16, 2014 |
# ¿ Aug 16, 2014 05:29 |
|
Ithaqua posted:I've taken a similar approach (the COM stuff sucks). But why not use PowerShell to set the time in the XML instead of manually editing it? Thanks for taking the time to do this. I don't know powershell but I think I can piece together whats happening. I'm going to try it out later tonight and I'll let you know how it works out.
|
# ¿ Aug 16, 2014 23:17 |
|
Hughmoris posted:Thanks for taking the time to do this. I don't know powershell but I think I can piece together whats happening. I'm going to try it out later tonight and I'll let you know how it works out. Just to follow up, I attempted to create this PS script. I was unable to run the script due to being restricted by the system. After a little reading, I tried to allow it with: set-executionpolicy remotesigned. Received the error that I couldn't alter the regkey. So, there goes that. Not sure if our IT department will unlocked that for me. Either way, the higher ups want to start all this crap at 0830 Monday morning so it won't do me much good. I do have AutoIt installed on this workstation, so I guess I'll try and figure out how to write your script in AutoIt. Unless it would be easier to write some sort of command-prompt script.
|
# ¿ Aug 17, 2014 03:45 |
|
Is there an easy way to print a PDF file to a network printer, using powershell? I couldn't find an easy way to do it, so right now I'm having the script make the network printer be the default printer, then print to default printer.
Hughmoris fucked around with this message at 20:23 on May 5, 2015 |
# ¿ May 5, 2015 20:20 |
|
Ignore.
|
# ¿ May 5, 2015 20:21 |
|
Reiz posted:Are you using powershell 4? Get-Printer and Out-Printer should probably do what you need. There's also the .Net System.Drawing.Printing namespace which you could use with some effort: https://msdn.microsoft.com/en-us/library/system.drawing.printing%28v=vs.110%29.aspx I'm using Powershell 2. It's a work computer running Windows 7, and I'm a bit leery about trying to update powershell to a newer version. I'll have to take a look at that Namespace link you provided. The method I'm using now works but its a bit...awkward.
|
# ¿ May 6, 2015 00:25 |
|
Briantist posted:What are your concerns about upgrading powershell? If you already have .Net 4 then you just need to install WMF 4 to get it. I'm not too familiar with PS, and with it being a work computer I'm not sure if an upgrade would have a negative impact on anything else installed.
|
# ¿ May 7, 2015 01:21 |
|
Kind of stumped here. I'm working with a CSV and following this technet tutorial. My starting CSV is in this format: code:
and my output is this in this format: code:
code:
Hughmoris fucked around with this message at 03:17 on Jun 2, 2015 |
# ¿ Jun 2, 2015 03:14 |
|
Briantist posted:The important thing to remember is that you have an object, with properties, and you can view and manipulate it as you see fit. The way it's displaying at the moment is in "List" format, probbaly because PowerShell determined it would fit better that way or be too crammed in a table. You're the man! The solved my problem. Trying to fumble my way through automating some tasks at work and its amazing how easy PowerShell makes it. A quick google search showed me how simple it is to incorporate regex into the Where-Object command: code:
|
# ¿ Jun 2, 2015 03:39 |
|
Powershell was giving me fits earlier today when trying to accomplish a simple task. I have a file called patient.txt with contents similar to: code:
|
# ¿ Jul 3, 2015 04:15 |
|
Ithaqua posted:(get-content C:\temp\patient.txt) -match "^Location:+" Sorry, the question was very poorly worded. Now that I my work laptop with me, here is my input file (with fake patient info): code:
code:
Hughmoris fucked around with this message at 02:36 on Jul 8, 2015 |
# ¿ Jul 8, 2015 02:25 |
|
Briantist posted:I think I would do something like this: Thanks for this.
|
# ¿ Jul 9, 2015 00:49 |
|
Vague question but does anyone here use Powershell for things outside of sysadmin type work? For web scraping, text parsing, console applications etc...? I like exploring new languages but I'm not going to need it for any sort of administrator duties.
|
# ¿ Nov 3, 2016 01:33 |
|
I need some help with getting powershell to display glyphs correctly. I'll preface this by saying I don't have a great grasp on fonts/glyphs/unicode. I'm using powershell to execute some Perl 6 code. It is not properly displaying glyphs that are in the output. After some googling, I've installed Unifont and am using the Powershell ISE but it still fails to display properly. Here is what the output looks like: Any ideas?
|
# ¿ Nov 26, 2017 18:53 |
|
I'll give that a look. Thanks!
|
# ¿ Nov 26, 2017 21:33 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
A bit of a broad rookie question because I don't know what I don't know. I'm following some tutorials on Microsoft Entra ID. Instead of clicking through the portal, I want to complete the steps in PowerShell. With PowerShell, should I be using the Microsoft Graph module? Is the AzureAD module being deprecated for Graph, or am I misunderstanding the random rear end blog articles I've found.
|
# ¿ Dec 13, 2023 20:47 |
|
Potato Salad posted:I think you're overthinking this? If you want to make a new user, you cast New-AzureADUser. It....does that. Thanks!
|
# ¿ Dec 14, 2023 04:32 |
|
Rookie PowerShell question: If I'm running PS commands from the CLI, how would I selectively log certain executed commands to a CSV? Not the output, just the command/script executed and the time. In plain English, I think I need a My-Logger function so if I call: My-Logger Get-Process , it would append to my.csv the datetime and Get-Process. I'm new to PS and not sure how to approach this.
|
# ¿ Apr 15, 2024 17:25 |
|
Thanks for the ideas. I'm phone posting so forgive me. What I need is an "on the fly" ad-hoc way of saying "I want to log to a custom CSV the command/script I'm about to execute". I don't have a need to log other stuff I run. Maybe I can figure out a way to retroactively parse history for the info?
|
# ¿ Apr 15, 2024 17:53 |
|
Thanks for the idea! I learned something new with that Start-Transcript. It's a weird short-term thing that isn't totally necessary, just something that can save me a bit of manual data entry. I'm mainly poking at it to see if I can automate it. At this point I'm thinking I can add a comment (e.g. ##LogThis!) at the end of each relevant command execution, then write a simple script that parses History and finds those comments, writing those commands to a CSV along with their execution time.
|
# ¿ Apr 15, 2024 23:54 |
|
|
# ¿ Apr 29, 2024 04:03 |
|
Wizard of the Deep posted:I'm still not seeing what exactly you're trying to accomplish. Do you need to submit some kind of report of when you do a specific task? In that case, I'd honestly just auto-start a transcript as part of your profile.ps1, then grab the relevant data whenever you need to submit the report. Combine that with a Posh theme that auto-timestamps your prompt and you're probably golden. Pile Of Garbage posted:Is this potentially related to fulfilling some security thing (e.g. ACSC Essential Eight)? If so look at transcription/script block logging/module logging settings in Group Policy (Note you can enable these on a single machine via local Group Policy, aka gpedit.msc): https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_group_policy_settings?view=powershell-5.1 Thanks for the ideas. I was attending an informal training session where certain actions needed to be logged for review. I ended up just keying in ,or copy/pasting, what was needed. I have learned more about the transcripts and profiles after reading up on your suggestions.
|
# ¿ Apr 23, 2024 17:57 |