|
How does one get a list of proxyAddresses from AD with the users name with each proxyAddress in a separate row? For example: pre:| name | proxyAddress | -------------------------------- | user1 | email1@domain.com | | user1 | email2@domain.com | | user1 | email3@domain.com | | user2 | email1@domain.com | | user3 | email1@domain.com | | user1 | email2@domain.com | | user4 | email1@domain.com |
|
# ? Apr 16, 2014 20:57 |
|
|
# ? May 10, 2024 01:10 |
|
kiwid posted:How does one get a list of proxyAddresses from AD with the users name with each proxyAddress in a separate row? Pipe it into Format-Table?
|
# ? Apr 16, 2014 20:59 |
|
CLAM DOWN posted:Pipe it into Format-Table? Doesn't seem to work since proxyAddresses is a multi-value attribute.
|
# ? Apr 16, 2014 21:09 |
|
kiwid posted:Doesn't seem to work since proxyAddresses is a multi-value attribute. Foreach loop the attributes and then output?
|
# ? Apr 17, 2014 04:14 |
|
kiwid posted:How does one get a list of proxyAddresses from AD with the users name with each proxyAddress in a separate row? We're an O365 shop as well, so we've done a lot with powershell and AD/Exchange. For this issue, I basically stole the solution from this blog. Multivalue properties can be a little bit of a pain. My buddy at work is our 'powershell master' and he even wrote something that just pulls the @onmicrosoft.com proxy address from a user object. http://blogs.technet.com/b/heyscriptingguy/archive/2013/07/22/export-user-names-and-proxy-addresses-to-csv-file.aspx To comment on one of your previous posts kiwid posted:So, we've recently changed our policy for our help desk to start filling in all the fields in an Active Directory user that we never really cared about before, such as organization information, addresses, phone numbers, etc. We've also moved to Office 365 which requires manually editing the proxyAddresses attribute for alias email addresses. They aren't very consistent with filling this information out and often forget to connect home drives and poo poo. I want to create a dummy proof PowerShell script that goes through the process of creating a new user but my experience with PowerShell is running one off commands. If you guys had to choose one book (maybe two), to learn PowerShell (especially syntax), what would it be? Powershell in a month of lunches is really good. I would start there. We have some user onboard scripts written in powershell that completely automate the new user creation process, but they're written for bulk new users in our call center environment where 20,40,60 people have mostly the same attributes. If you can organize the data into a CSV file though, it's pretty easy to automate. You could also just write a script that prompts for each bit of data, that might work better. Helpdesk dude runs new_user.ps1 and then it prompts for First Name Last Name Logon Name Email Address <whatever else you want> etc. Then you can throw in some logging, it's really just a matter of what you want to do with powershell.
|
# ? Apr 17, 2014 15:06 |
|
skipdogg posted:We're an O365 shop as well, so we've done a lot with powershell and AD/Exchange. Awesome thanks, yeah I saw that blog but we have accounts with like 40 alias email addresses. I did modify his script though and then just end up using Excel's Text to Columns feature. This is the command I used: code:
skipdogg posted:To comment on one of your previous posts Having a script prompt for everything would ideally be the best way for our help desk to do this. Then at the end of the script, list all the information and ask if everything is correct and to submit or if something is wrong/mistyped, cancel, or better yet, allow them to fix that attribute. I have no idea how to do this though. My programming skills are limited to PHP.
|
# ? Apr 17, 2014 17:02 |
|
You can pipe your Get-ADuser into a nested foreach to get that, but the big question is "Why?" since you can output to csv or a text file (or actually do something with the addresses) much easier than trying to display a formatted table in the shell window. In any case, I had to play with it a little and here's what I got (it's a bit messy)code:
quote:Having a script prompt for everything would ideally be the best way for our help desk to do this. Then at the end of the script, list all the information and ask if everything is correct and to submit or if something is wrong/mistyped, cancel, or better yet, allow them to fix that attribute. I have no idea how to do this though. My programming skills are limited to PHP. It would be pretty simple to brute force your way through this. Have a bunch of hardcoded variables, Read-Host to set the variables to whatever you want, and then use New-ADuser and Set-ADuser to apply the appropriate information to the appropriate place. e: The only gotcha with this is that I believe setting extension attributes (or in general, any weird AD attribute) requires you to pass a hash table or some other weird thing. I don't believe it's as easy as Set-ADUser -extensionattribute1 Foo -extensionattribute2 Bar, and so on. I haven't really played with it myself, though. 12 rats tied together fucked around with this message at 19:31 on Apr 17, 2014 |
# ? Apr 17, 2014 19:27 |
|
Reiz posted:It would be pretty simple to brute force your way through this. Alright, so I spent today brute forcing together a script and it works pretty well. However, there is one thing I don't know how to validate. At the end of the script when I actually execute the New-ADUser command, how can I tell programmatically if it was successful or failed? Does the command have any return codes to check? The only thing I can think of is to immediately run a Get-ADUser command to see if the new account exists.
|
# ? Apr 22, 2014 02:58 |
|
You could use -PassThru, which will return the created object. My guess is that if it fails it will just fail and die out.
|
# ? Apr 22, 2014 05:07 |
|
I'm drawing a blank with what I'm pretty sure is a simple thing, it's driving me nuts. I want to import a CSV, iterate through each line, if there are multiple entries on a line separated by a semicolon, split them up into multiple lines, and write them to a new file. Input file looks like this: code:
code:
code:
code:
So the output somehow is grabbing the length of each line rather than the content. Am I going about this in the completely wrong way?
|
# ? Apr 25, 2014 00:28 |
|
Is it possible that powershell is assuming you want to add (since you're using += and powershell is weird about that) the length of $outputcsv to $splitline (0 + whatever), and then writing that to file? There might also be an issue with you using import-csv instead of get-content. I don't really use import-csv a whole lot but I was under the impression that it creates objects from your CSV, so I could see that possibly being an issue as well. Is Length the first property in your csv?
|
# ? Apr 25, 2014 15:11 |
|
Reiz posted:Is it possible that powershell is assuming you want to add (since you're using += and powershell is weird about that) the length of $outputcsv to $splitline (0 + whatever), and then writing that to file? The imported CSV only has one property/column, the value as shown, there is no length property or intentional calculation of the length anywhere. I'm using import/export-csv because it's just something I'm used to. It also has a really easy way of handling headers with -Header. I'd definitely want to switch to something better/newer like Get-Content but I'm not sure I have the time with this one. Same with the +=, I was used to using stuff like this from other languages. I may have to try a different approach here.
|
# ? Apr 25, 2014 16:12 |
|
Maybe define $outputcsv before the loop (assuming you weren't already) just so powershell knows it's an array:code:
code:
Jethro fucked around with this message at 19:08 on Apr 25, 2014 |
# ? Apr 25, 2014 18:55 |
|
quote:The imported CSV only has one property/column, the value as shown, there is no length property or intentional calculation of the length anywhere. That is very strange; I'd be really interested in where it's pulling the Length property from, then. But, in this case (which I'm reading as: you have a text file and want to split it up on the semicolon), I would probably just use: edit: You probably don't want the semicolons code:
code:
12 rats tied together fucked around with this message at 01:02 on Apr 26, 2014 |
# ? Apr 26, 2014 00:16 |
|
What is the best way to capture all the output of a Powershell script running via task scheduler to a log file? I'm trying to troubleshoot some scripts that I have that are failing and finding the lovely method that I implemented is not capturing all the commands or variables.
|
# ? Apr 27, 2014 20:11 |
So I have to do a big broad discovery for a consultant. I need to get some hardware stats - disk space, make/model, etc. - and it looks like I can use get-wmiobject to do so. (I'm open to other methods, so long as I can gather total disk space, used disk space, etc.) I was able to use get-adcomputer to get a list of all computer objects in AD, and I've piped it to an array. But whenever I run the command below in Powershell with Active Directory module (logged on as a domain admin, launching Powershell as administrator): code:
code:
Our environment has Windows Firewall off for all connections via group policy, and we don't filter or firewall any internal traffic. I used Lansweeper Connectiontester to test connections, and it shows port 135 as open and WMI access tests OK to any computers I use. I am running all this from one of our domain controllers. Anyone know what else I should be trying? Edit: I can rpcping other machines without issue from the domain controller I'm using for this. MJP fucked around with this message at 14:25 on Apr 28, 2014 |
|
# ? Apr 28, 2014 13:40 |
|
This might be a little silly but have you tried doing enable-psremoting on all of the target machines? There were a shitload of hoops we had to jump through to get all of our desktop machines remote-powershell friendly. You should also double check that the WinRM service is running on all the target machines (Test-WsMan). While you're jumping through all these hoops you might want to enable CredSSP authentication too, which allows your remote sessions to use your passed credentials to authenticate against a third machine (Say, you want to run an installer or write to a log file located on a server). With get-wmiobject I usually get RPC errors when trying to grab from machines that aren't online, that obviously isn't the case for you at the moment. What happens when you try to Enter-PSSession? Get-WMIObject usually takes a long rear end time, have you tried it specifically against one computer that you know is online right now? Also, for when you do actually get powershell remoting working, it might make your job a lot easier to know that you can Get-WmiObject -class win32_logicaldisk | select PSComputerName,DeviceID,Size,Freespace,VolumeName | export-csv .\diskspace.csv -append To get a full list of all of the properties of a win32_logicaldisk wmi object, you can pipe it into Get-Member (shows all properties and methods) or Select * (shows all properties and their values). Reiz posted:That is very strange; I'd be really interested in where it's pulling the Length property from, then. code:
|
# ? Apr 28, 2014 15:06 |
|
MJP posted:So I have to do a big broad discovery for a consultant. I need to get some hardware stats - disk space, make/model, etc. - and it looks like I can use get-wmiobject to do so. (I'm open to other methods, so long as I can gather total disk space, used disk space, etc.) Also, what happens when you manually run Get-WmiObject for one of the computers in question?
|
# ? Apr 28, 2014 15:39 |
|
ghostinmyshell posted:What is the best way to capture all the output of a Powershell script running via task scheduler to a log file? I'm trying to troubleshoot some scripts that I have that are failing and finding the lovely method that I implemented is not capturing all the commands or variables. Start-Transcript should work for you.
|
# ? Apr 28, 2014 15:44 |
|
Fenrisulfr posted:Start-Transcript should work for you. This looks like it will work well, but now I can't use the Powershell ISE. Is there another popular IDE I can use with this command and powershell? Otherwise, thanks, I will just notepad it up from now on, but this will do the trick for me.
|
# ? Apr 28, 2014 16:48 |
|
Reiz posted:post Just wanted to say thanks to you and others for the tips, I'm gonna give these a try today. I was so frustrated with this Friday that I shelved it for the weekend, but it's definitely something I want to fix by the end of this work week. Will post here if I manage to get it working how I want.
|
# ? Apr 28, 2014 17:10 |
|
ghostinmyshell posted:This looks like it will work well, but now I can't use the Powershell ISE. Is there another popular IDE I can use with this command and powershell? You should be able to add something like this into your script: code:
and then close it at the bottom with Stop-Transcript
|
# ? Apr 28, 2014 17:26 |
Jethro posted:Are you sure $computers is an array of strings, as opposed to some sort of array of ad results or something like that? $computers is a list of computers. I took an export from get-adcomputer piped to CSV, removed all other columns and rows not in use, saved as CSV, and confirmed that there were no trailing spaces. So it should fit a list of string values. If I run get-wmiobject against a remote computer manually, it runs just fine.
|
|
# ? Apr 28, 2014 18:00 |
|
MJP posted:$computers is a list of computers. I took an export from get-adcomputer piped to CSV, removed all other columns and rows not in use, saved as CSV, and confirmed that there were no trailing spaces. So it should fit a list of string values. Get-Adcomputer returns a list of Microsoft.ActiveDirectory.Management.ADComputer objects, not a list of strings. So maybe something like code:
|
# ? Apr 28, 2014 18:54 |
|
Ithaqua posted:For the record, parsing HTML with regexes is not recommended. Something like the HTML Agility Pack would make your life much easier. Djimi posted:I've outlined all the cases and the structure is guaranteed. I'd really rather not have to install anything. code:
|
# ? May 11, 2014 06:33 |
|
MJP posted:So I have to do a big broad discovery for a consultant. I need to get some hardware stats - disk space, make/model, etc. - and it looks like I can use get-wmiobject to do so. (I'm open to other methods...) Mainly I think you should make workstations report the information themselves instead attempting to run it off the DC or a member server. The method(s) below have been in place for over two years and it is pretty handy. When we were running all XP, my script was all batch because of the lack of PoSH on machines. Then I transitioned to PoSH and installed it on machines if it wasn't present (on XP) clients. My method has been: 1) group policy on domain for a startup script for all computers (within a group, if you don't want servers etc.) 2) startup script copies a local ps1 script to each machine. And creates system task that 3) each machine runs the script once an hour. 4) each output of a machine status (log file) is copied to server directory as page of information for the workstation as well as a secondary file that is a single line of text as comma separated values. (I call this the tail log). 5) Once a day the server share runs a task to collate all the csv lines into one large appended csv. 6) Immediately after that a second script as a task takes that large csv and creates an html file with links by hostname to the individual logs of the workstations (more easily read as a text file in a browser, if you just want to check out a single host). This is really just a nice way to look up a computer and click to link to a page of information instead of scrolling horizontally on a large spreadsheet. Really not needed, but nice. Specifically if you want to figure out diskspace stuff here's my code for that and a few more tasty bits as well: code:
The code for that is the beginning of the script: code:
code:
I just print out "execution time: " + $start + " to " + $end Anyway, it may not be for your particular needs, but every machine joined to the domain starts reporting back and everyday at 4:30 p.m. I have a current, accurate spreadsheet and html file to refer to of every workstation or server. I also rotate (rename) the prior day's collated csv log (step 5). So I have a historical record as well. Next I would say I should inject everything in a MySQL server and serve that up.
|
# ? May 11, 2014 07:35 |
|
How have I been doing so much PowerShell lately, but not known about out-gridview until yesterday?
|
# ? May 14, 2014 18:54 |
|
Ithaqua posted:How have I been doing so much PowerShell lately, but not known about out-gridview until yesterday? That's part of my PowerShell sales pitch to people who aren't sure it's worth learning. You already know all sorts of cool DOS commands, right? Now you can supplement them with the pipe, try "arp -a" Now try "arp -a | out-gridview"
|
# ? May 14, 2014 19:00 |
|
MJP posted:So I have to do a big broad discovery for a consultant. I need to get some hardware stats - disk space, make/model, etc. - and it looks like I can use get-wmiobject to do so. (I'm open to other methods, so long as I can gather total disk space, used disk space, etc.) Is there some reason you cant just use PDQ Inventory? It does what you're asking for and it's free. http://www.adminarsenal.com/pdq-inventory I use it every day at work and find it to be invaluable
|
# ? May 15, 2014 00:37 |
|
What's the best way to get started on DSC? I consider myself pretty experienced and skilled with Powershell, but the majority of my scripting has been on 2.0, only very recently in 3.0. I'd really like to learn DSC and start using it as the Linux management in v5 is an incredibly attractive option for us.
|
# ? May 15, 2014 18:24 |
|
Dr. Arbitrary posted:That's part of my PowerShell sales pitch to people who aren't sure it's worth learning. You already know all sorts of cool DOS commands, right? Now you can supplement them with the pipe, try "arp -a" I tried this yesterday and gasped. It was like the aliens from Toy Story when the claw comes out. I IMed it another guy I work with and he did same thing. Amazing.
|
# ? May 15, 2014 18:27 |
|
CLAM DOWN posted:What's the best way to get started on DSC? I consider myself pretty experienced and skilled with Powershell, but the majority of my scripting has been on 2.0, only very recently in 3.0. I'd really like to learn DSC and start using it as the Linux management in v5 is an incredibly attractive option for us. I've been doing a lot of messing around with DSC lately. It's not very well documented, and it feels like it's very limited out-of-the-box. Most of the stuff you'd actually want to use it for is being accomplished via unsupported community extensions. IMHO it's not mature enough for prime-time yet. Soon, but not yet.
|
# ? May 15, 2014 18:48 |
|
The Electronaut posted:
Thank you for letting me know. I'm on my second year in IT and if you look through my post history it's a lot of "how do I do x?" and "why does z?" I'm glad that I get to give back a little bit.
|
# ? May 16, 2014 04:05 |
|
I've got a script currently that tests the websites/apps my employer hosts. One of the tests involves detecting a popup and I'm struggling to come up with a way to detect it. I've played around a little with opening the popup and then using Shell.Application and assigning a dummy variable to basically Shell.Application.Windows() | ? { $_.LocationURL -eq "whatever" }, but I can't get it to 'stick'. While messing around with the windows() method I noticed that it wasn't pulling any of the IE processes I had running at all, despite multiples of them running. It's a fairly simple check, I just need to see if the LocationURL or body contains a string which will give me a pass/fail. I don't even really need to control the popup directly - as long as I can detect that it exists and check properties of it I can probably work something out. I'm really clueless as to why windows() was barely detecting anything, though. Any thoughts? Is there a better way to do this?
|
# ? May 20, 2014 06:29 |
|
Dr. Arbitrary and Ithaqua posted:out-gridview" Wow thanks for this. I think this is my new favourite thing.
|
# ? May 21, 2014 02:32 |
|
Reiz posted:It's a fairly simple check, I just need to see if the LocationURL or body contains a string which will give me a pass/fail. I don't even really need to control the popup directly - as long as I can detect that it exists and check properties of it I can probably work something out. I'm really clueless as to why windows() was barely detecting anything, though. Any thoughts? Is there a better way to do this? I believe the issue here is something to do with namespaces or resource providers or some other windows thing. I'm running powershell as an admin on an account that isn't an admin and the IE processes are being created under admin but displayed on user and it seems like they hook into a process running as system. From what I understand windows() either isn't looking or can't look in the right place to detect any IE windows I don't open manually. New question: what's the deal with capturing named groups with regex in powershell? Normally I test my regexes in sublime text and they work out fine, but this time I feel like the interpreter is doing something funny. I'm pulling XML from share point and looking for everything between a tag using basically (?<=URL=") (.*?) (?=\"). In sublime text it matches fine, in powershell it matches absolutely nothing. I've confirmed I'm matching against a string, I've even matched XML from share point before (although with a simpler regex). I can give examples later when I'm not phone posting.
|
# ? May 22, 2014 18:25 |
|
DSC is pissing me off right now. First off: How do I push custom modules to remote boxes? I'm trying to use the PowerShell DSC Resource Kit, and I don't want to install it on the servers manually. That's dumb. Second: The PowerShell DSC Resource Kit is a big piece of poo poo as far as I can tell. Nothing works exactly as advertised. Trying to create a website? Nope, that's going to fail because the site doesn't exist. Trying to deploy a service? Nope! As far as I can tell, you can't do the world's most basic "service installation" workflow: Stop service if it exists. Copy binaries. Create service if it doesn't exist. Start it.
|
# ? May 22, 2014 20:50 |
|
Dr. Arbitrary posted:Thank you for letting me know. I'm on my second year in IT and if you look through my post history it's a lot of "how do I do x?" and "why does z?" I had a very similar Toy Story moment too when I saw it. It makes dealing with Exchange logs so much easier. Thanks
|
# ? Jun 5, 2014 09:03 |
|
Ok, so I'm trying to pull AD info, sort and parse by username, profilepath, and home directory. I then want to dump users with correct profilepath/home directory in one file, and dump the incorrect profilepath/homedirectory users into another file. Parse incorrect file with users with no profilepath and home directory vs those that do. Show users with incorrect profile path and home directory. Then I want to have a script for changing and setting the new users profile data. As I'm still just starting with this, I'm having issues understanding why certain commands work while others keep giving me errors. code:
|
# ? Jun 18, 2014 15:37 |
|
|
# ? May 10, 2024 01:10 |
|
fromoutofnowhere posted:Ok, so I'm trying to pull AD info, sort and parse by username, profilepath, and home directory. I then want to dump users with correct profilepath/home directory in one file, and dump the incorrect profilepath/homedirectory users into another file. Parse incorrect file with users with no profilepath and home directory vs those that do. Show users with incorrect profile path and home directory. The format- commands are for rendering the data, use select to get those two properties.
|
# ? Jun 19, 2014 02:48 |