|
Thank you so much The Electronaut! After banging my head against the wall just giving the term "select" basically gave me what I needed to work out what I was doing. Finished this today and will create the script to use this data to change the profiles later. Get-ADUser -filter * -properties profilepath, homedirectory | select-object Name, profilepath, homedirectory | format-list > c:\temp\test1.csv Get-content -path c:\temp\test1.csv | foreach-object {$_ -replace "\\Filenamex", "\\Filenamey"} | set-content c:\temp\test2.csv edit: search - select, same thing. fromoutofnowhere fucked around with this message at 15:19 on Jun 19, 2014 |
# ? Jun 19, 2014 14:42 |
|
|
# ? May 15, 2024 04:09 |
|
fromoutofnowhere posted:Thank you so much The Electronaut! After banging my head against the wall just giving the term "select" basically gave me what I needed to work out what I was doing. Haha. Great! I've done something very similar and even have it saved off but I was out and about away from my repository so couldn't just paste bin. Something to concern yourself with longer term, the AD cmdlets kind of suck IMO and prefer to use LDAP for data gathering most of the time, same with the Exchange cmdlets that hit AD for their data.
|
# ? Jun 19, 2014 17:37 |
|
Something to keep in mind is that you can take an array and just pipe it into ForEach-Object if you want to iterate through it. So, you probably don't even need to generate test1.csv or test2.csv - not that it really matters since you've already accomplished your goal/task, but it's kind of a sloppy habit (IMO) that I see everywhere when it comes to powershell. You might have to play around with it a little, but generally you can do things like: code:
I actually just had this exact problem (sort of) about a month ago where our AD users' Extension Attribute was being set improperly by a (crappy) new user powershell script that someone had written a few years ago and nobody had any clue what was happening in it. My boss wanted me to set everyone's extension attribute (150+ people) to the number identified in the Sharepoint list that HR was keeping track of, and it was fairly easy. Invoke-WebRequest the sharepoint list, select -expand content, regex into an array containing Name,Extension. ForEach-Object, Get-ADUser where $_.name -like name, and then $_.extAttribute = Extension. In general I feel like you lose a lot of the object oriented functionality (and convenience) of Powershell if you are constantly pounding everything out into a CSV. It's faster to write, easier to understand and maintain, and IMO just makes more sense if you use the framework that already exists instead of trying to brute force your way through yourself. I also notice that a lot of people seem to focus on Powershell's ability to Get the information they want, so they can then format it in some way, look at it, and then do something. Something I see a lot of people overlook is that powershell can actually do the Getting, Looking, and Doing for you - I actually consider Format-Table/List (ft,fl) and Out-GridView to be mostly useless for this reason. If the task is so simple that I am going to be manually completing a part of it, I can just look up the information myself. If looking up the information is too time consuming, I script the entire process.
|
# ? Jun 22, 2014 21:48 |
|
I wish there was a way to use the PS 4.0 SMB cmdlets in Server 2008 R2, I'm going nuts trying to incorporate net share or subinacl into my script
|
# ? Jul 4, 2014 17:14 |
|
I'm trying to user Powershell to set permissions on an OU in AD. I can set the permissions on the OU itself just fine, however I need them to also apply to all descendent objects as well, and they do not. I can't for the life of me figure out how to do it. Here's my code:code:
|
# ? Jul 7, 2014 13:02 |
|
I am trying to do some authentication for file shares cleanly and compactly. Say I could have a tedious number of remote machines with a common file share structure to which I want to manage some files. These machines can have different logins, although most are the same. I was hoping there was an easy way to only prompt for credentials the first time I need to use a different login. So there may be 20 machines I can login to using login/password ABC/123, and 30 more than do XYZ/789. I was hoping to at most only get two prompts in that case for the login credentials. I'd also hope to hide the password. Is there a way I can get into that without having to try New-PSDrive then react if there's a login problem?
|
# ? Jul 10, 2014 21:54 |
|
Rocko Bonaparte posted:I am trying to do some authentication for file shares cleanly and compactly. Say I could have a tedious number of remote machines with a common file share structure to which I want to manage some files. The easiest way to do this would probably involve Try, Catch. You can assign the credentials to two variables, do a try { do-thing $credentials_1 } catch { do-thing $credentials_2 }. You'll probably have to fiddle with the catch, it doesn't always catch like I expect it to, but to be fair I almost never use it. Another way would be to separate the servers out, if they aren't changing dynamically or anything. You have two arrays, each one contains a series of hostname strings for each set of credentials. $array_credentials1 | ForEach-Object { Do-Thing -action -computername $_ }; $array_credentials2 | ForEach-Object {Do_Thing -action -computername $_ }. If the password changes dynamically but is stored in say, a spreadsheet somewhere? Or maybe a sharepoint list? SQL database? You can get the content of that location with Get-Content, System.Data.SqlClient.SqlCommand, or Invoke-WebRequest, and then regex it and grab the password. With CSVs, you can do Import-CSV to generate objects based on the CSV, etc. So the simple answer is that there are a lot of ways to do this but it depends on what you're doing and how you get the credentials. I could provide better suggestions with some more info. However, I would also be somewhat concerned that you would need to use two logins for anything at all. Some background on the logins, specifically, would also be useful. You can also use test-path to generate a true/false for your current access rights to a location - it would be pretty easy to do a if $access -eq $true { do thing }, else { do-thing -with other credentials }. quote:I'm trying to user Powershell to set permissions on an OU in AD. I can set the permissions on the OU itself just fine, however I need them to also apply to all descendent objects as well, and they do not. I can't for the life of me figure out how to do it. code:
12 rats tied together fucked around with this message at 08:19 on Jul 11, 2014 |
# ? Jul 11, 2014 08:16 |
|
Can somebody tell me what I'm doing wrong here? I'm trying to write a script that creates a DL and adds members all at once.code:
I've tried adding a start-sleep to give it time to create the DL, still no good. EDIT: Ignore this dumb post, added a do...while to check for existence. ElGroucho fucked around with this message at 20:10 on Jul 11, 2014 |
# ? Jul 11, 2014 19:35 |
|
I am trying to import a CSV of AD users and related data, then do a compare against existing data, make a change if required and the log it out to a text file. It's fairly trivial to just blanket overwrite everything with the CSV data, but I'd rather do a compare and handle it a bit more gracefully. I can never get IF statements to work well in this context, if at all, is this a limitation that exists when using Import-CSV?
|
# ? Jul 15, 2014 16:05 |
|
Without being able to see your script and any of the error messages, I would say the most common mistake I see people making with Import-CSV is that it constructs objects based on the text file, so you probably need to dot source based on the array index variable. For example if you're doing in the compare in a for-loop it should look something like: (this is clunky for clarity's sake) code:
I wanna say, usually when I see this kind of error I'm trying to do something with Invoke-Command and run it remotely on several computers at once. Generally, I fix it by by specifically assigning sub-variables (such as $CurrentProperty = $_.Property), which I think is pretty sloppy. Other times I'll just realize that what I'm trying to do is stupid and do it some other, better way.
|
# ? Jul 16, 2014 04:23 |
|
Reiz posted:Admittedly, I've never tried to do this. However, I'd be interested in seeing any error messages you get when you run $acl.AddAccessRule($ace). I feel like your formatting is off when you are constructing the class. In particular, if you take a look at the constructor page: click You're right, I'd accidentally posted one of my attempts that didn't actually work. The line that does work is: code:
I think I'm doing something fundamentally wrong here, because when I look at the results of Get-ACL when the permission is applied to child objects and when it's not, the ACL is in fact identical. So I wonder if there's another command that sets inheritance.
|
# ? Jul 18, 2014 18:04 |
|
Dumb question: I know that when specifying a directory for a variable, in order to go up one directory you just type ".\" in front of the directory name ($LogPath = ".\Logs"), but what if I want to go up two directories?
|
# ? Jul 24, 2014 20:10 |
|
To up one level you would go to .. so in your example it would be $LogPath = "..\Logs". To go up two levels just keep doing the same, "..\..\Logs" etc etc.
|
# ? Jul 24, 2014 20:21 |
|
FISHMANPET posted:To up one level you would go to .. so in your example it would be $LogPath = "..\Logs". To go up two levels just keep doing the same, "..\..\Logs" etc etc. Thank you for this. It works just fine when I run it in the PS ISE, but when I run it the way I'm trying to get it to work I get a "directory not found error". I'm confused as to why this is. Edit- Ok, so it looks like ..\..\ was bringing me up one more than I wanted. "..\" works perfectly to go up two, and for one directory ".\" works. Did I interpret your answer wrong? I have a VB.net Windows Form GUI that kicks off a batch file that then kicks off a PS script. VB snippet- code:
code:
code:
TheEffect fucked around with this message at 21:13 on Jul 24, 2014 |
# ? Jul 24, 2014 21:07 |
|
I'm missing something very, very obvious. How do I return values from Powershell functions? code:
I have functions that need to return certain info, including variables, for use in the rest of the script. What change would I need to make to the above script to print "hello world!"?
|
# ? Jul 24, 2014 21:45 |
|
code:
|
# ? Jul 24, 2014 21:49 |
|
That did it! Thank you. Some of the articles on "return in powershell" were misleading about how return works and doesn't work, and totally pointed me in the wrong direction.
|
# ? Jul 24, 2014 22:03 |
|
TheEffect posted:Edit- Ok, so it looks like ..\..\ was bringing me up one more than I wanted. "..\" works perfectly to go up two, and for one directory ".\" works. Did I interpret your answer wrong? Let's say you're in C:\Foo\Bar\Baz\ . = C:\Foo\Bar\Baz\ .\.. = C:\Foo\Bar\ .\..\.. = C:\Foo\ etc "." is the current directory, not "up" anything.
|
# ? Jul 24, 2014 22:05 |
|
What's the proper way to grab a field from an array when the key is a string? For example:code:
code:
code:
|
# ? Jul 25, 2014 02:25 |
|
Karthe posted:What's the proper way to grab a field from an array when the key is a string? For example: [edit] Is this what you're after? code:
code:
code:
code:
New Yorp New Yorp fucked around with this message at 03:39 on Jul 25, 2014 |
# ? Jul 25, 2014 03:22 |
|
Sorry, I should have realized the code would be too ambiguous. What I'm trying to do is export some lists from Sharepoint into a CSV file. Right now I'm trying to make a single function that is flexible enough to take a List name, identifier for the CSV file, and a list of FieldValues and produce the desired CSV file. Here's a more thorough bit of code: code:
pre:"Title","GroupCode" "LA","LA" "NY","NY" "TK","TK" pre:"Title","GroupCode" "Los Angeles","LA" "New York","NY" "Tokyo","TK" For thoroughness sake, here's code that produces the desired result: code:
IAmKale fucked around with this message at 15:07 on Jul 25, 2014 |
# ? Jul 25, 2014 05:17 |
|
Ithaqua posted:Let's say you're in C:\Foo\Bar\Baz\ I see. Thank you for explaining something so simple to this newbie.
|
# ? Jul 25, 2014 16:13 |
|
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 |
|
Hughmoris posted:In PowerShell, how do I loop through a text file and insert "Sleep(500)" in between each line? get-content .\test.txt | % { $_ + [System.Environment]::NewLine +"Sleep(500)" } | set-content .\output.txt
|
# ? Jul 25, 2014 19:02 |
|
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 |
|
Hughmoris posted:Thank you for this. I'll break it down: code:
code:
code:
So for every line ($_), we're appending [System.Environment]::NewLine (a .NET thing that just maps to \r\n or \n, depending on OS), then appending the "Sleep(500)" text to that. code:
|
# ? Jul 25, 2014 19:59 |
|
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 |
|
Hughmoris posted: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. 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.
|
# ? Jul 28, 2014 22:34 |
|
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 |
|
Hughmoris posted: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. 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. That said, give Coded UI a shot if you have access to a Visual Studio SKU that supports it. It might be able to read the IDs of all of the controls, although it's a crapshoot.
|
# ? Jul 28, 2014 23:56 |
|
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. I agree with you 100%, the vendor should be during their due diligence, but we find so many bugs during our UAT process (which is painstakingly boring and repetitive) that it's not safe for us to deploy new software without first making sure it's 100% fit for use and there won't be any adverse client, or internal, impact. We're talking major vendors too.
|
# ? Jul 29, 2014 15:17 |
|
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.
|
# ? Jul 29, 2014 15:21 |
|
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 |
|
If you can get the forms to work in a browser then that is easier -- check out http://docs.seleniumhq.org/ for a good tool.
|
# ? Jul 29, 2014 16:16 |
|
Reiz posted:Without being able to see your script and any of the error messages, I would say the most common mistake I see people making with Import-CSV is that it constructs objects based on the text file, so you probably need to dot source based on the array index variable. For example if you're doing in the compare in a for-loop it should look something like: You got me on the right path to getting this sorted, thank you very much. Now, I am trying to rig up a way to automatically remove all disabled accounts from the address lists in Exchange, and this works just fine EXCEPT it also hides all the conference rooms as well. code:
|
# ? Jul 29, 2014 21:04 |
|
You can chain wheres so if there is a way to say "where name not like conference-room-xxx" or something like that you'd be golden. No idea if there is an effective naming convention you can leverage. Another idea would be to add a piece of metadata to cover "accounts that are disabled but should not be hidden" and then filter on that. Would probably be better than relying upon naming conventions.
|
# ? Jul 29, 2014 21:52 |
|
So I could have it work like: Get-Mailbox Blah Blah | Where Account is Disabled | Where account does NOT have "Conference" in the name | Remove it from the lists That sort of chaining works?
|
# ? Jul 30, 2014 15:03 |
|
That works, though I don't see why you'd need to do that when you could just use -and.code:
|
# ? Jul 30, 2014 15:54 |
|
Bizarre question. I am trying to use Powershell to search HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ for a Registry Key (folder?) with a Display Name of “HP Theft Recovery” and then delete that key. Is this even possible? Back story is that I have an HP bloatware removal script that uses msiexec to uninstall the software, but Theft Recovery remains with a broken uninstaller in the Programs list that I'd like to remove... unfortunately the folder name changes with the GUID but the display name within the key always remains the same. Edit: Figured it out. Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | ? {$_.GetValue('DisplayName') -match 'HP Theft Recovery'} | Remove-Item dox fucked around with this message at 04:37 on Aug 1, 2014 |
# ? Aug 1, 2014 04:06 |
|
|
# ? May 15, 2024 04:09 |
|
Once again stuck on something very simple. I'm trying to remotely execute an MSI installer on a remote computer.code:
However, running the exact same command locally on the target computer works. code:
capitalcomma fucked around with this message at 18:37 on Aug 2, 2014 |
# ? Aug 2, 2014 05:24 |