|
When I import the AD module I get problems because the domain controller isn't running AD Web services. I'm trying to get a home lab set up ASAP so I can start learning how it's all supposed to really work.
|
# ? Oct 19, 2013 04:40 |
|
|
# ? May 21, 2024 12:30 |
|
You need to run AD Web Services to use the AD PowerShell module, yeah (and ADAC).
|
# ? Oct 19, 2013 14:03 |
|
Scikar posted:I might not be understanding right (I'm not great with coding jargon) but I think Get-Acl is already one step ahead of you. The object you get as output is just a copy of the ACL, if you make any changes to it then you still need to apply them to a target with Set-Acl (or equivalent) afterwards. Sorry for responding so late, but I was out last week and forgot about this. It would help if I explained my intentions better. The script is meant to verify the validity of existing permissions of a folder, then correct, remove, or add access control entries as necessary (or as requested by the user). I noticed the code to do this was all over the place so thought I'd create a function for both add and remove. I don't think I'll mess with this much more though, since I can easily accomplish this by making the ACL a global variable. Just trying to do things the right way, is all. Update: Figured out the problem. While I can't explain exactly why it works this way, I can at least move on. code:
Drighton fucked around with this message at 17:36 on Oct 23, 2013 |
# ? Oct 21, 2013 14:26 |
|
code:
code:
|
# ? Oct 24, 2013 17:43 |
|
You have a syntax error. Don't use foreach-object, just use foreach Or do this: ForEach-Object $a {Get-ADGroupMember -Identity $_ | get-aduser -properties * | select SamAccountName, displayname}
|
# ? Oct 24, 2013 18:42 |
|
By the way all the problems people have getting the AD cmd-lets to work (making sure you are on right version, right module is install on right computer, right things enabled on X) are pretty much the reason I'm going to say, again, you're better off learning the Directory Services .net namespace and how to use it in powershell as it's always available and it's all the AD-cmdlets are using in the background anyway.
|
# ? Oct 25, 2013 05:54 |
|
Can someone help me set up multiple windows paths in powershell? As far as i understand now i can only have 1 which i use for python. Id like to be able to have some more so that i can use ipython and pip without having to change my enviorment path all the time.
|
# ? Oct 25, 2013 12:11 |
|
Quick question regarding this script (a friend wrote it and I tweaked it): http://pastebin.com/RRxeK3CF If I wanted to return only servers that match a certain part of the results on the 'logonserver' portion, or the 'NTP Source' result, how could I do that?
|
# ? Oct 25, 2013 22:59 |
|
Wicaeed posted:Quick question regarding this script (a friend wrote it and I tweaked it): If I understand what you want correctly something like this would be the fastest way but ughhhh code:
code:
|
# ? Oct 26, 2013 03:57 |
|
Does Powershell 3.0 have any new ways to handle the pagefile? I have some code that uses the old WMI method (ie. get-wmiobject Win32_PageFileusage | select AllocatedBaseSize) but I'd love it if they added a new way to handle this.
|
# ? Oct 29, 2013 22:55 |
|
Finally got off my arse and wrote a script to rename folders dumped from my camera into something more suitable for long term storage. The camera makes a number of folders with the naming pattern "<three digit autoincrementing number><last digit of year>MMDD" and I want to rename them to the pattern "YYYYMMDD_<index padded to 3 digits>". The following works, but is there anything I should be doing different? code:
|
# ? Oct 31, 2013 13:50 |
|
adaz posted:
If you're using PSv3 you can score more points by doing this with PSCustomObject, which is about 30x faster: code:
code:
|
# ? Nov 2, 2013 14:30 |
|
I've been messing around with Desired State Configuration and it seems pretty awesome so far, how have you all been finding it/using it?
|
# ? Nov 5, 2013 23:41 |
|
I'm trying to write a command to restart a service on a remote PC but I get a return value of 5, access denied. I've tried it by using WMI and with Stop-Service. I'm posting from a phone so it's hard to post the code.
|
# ? Nov 11, 2013 00:37 |
|
adaz posted:Each SQL query is unique? How many are there? Is there any reason why you need to exclude the leftmost column as opposed to just not querying for that data? Holy quote from the dead. This has problems (thank you though for posting this, I've had in the back of my mind a common thing I've been wanting to get automated but have been scratching my head how to do it, load the SQL modules in, leverage sqlcmd, etc.) with queries that take longer than 30 seconds to run. I re-wrote it: code:
|
# ? Nov 11, 2013 17:09 |
|
I just picked up the morelunches.com Powershell3 in a month of lunches book. It's supposed to be a good starter for somebody with no experience in scripting languages. I guess I'll see if I can put something together at the end, like maybe automatically making a distribution list or something that I'm sure should be easy.
|
# ? Nov 17, 2013 12:13 |
|
I spent about 30+ minutes on the internet and did a few searches in the cavern here for figuring out my attempt to find/replace with regex matching and using the found pattern in the replacement to create links to other files. The only matches / replacements I need are the beginning of the line in an html table page, so I should be able to anchor with ^. I don't know powershell that well, and I'm probably worse in regex A line in the file to find/replace would be: code:
code:
Thanks in advance
|
# ? Nov 18, 2013 22:04 |
|
Djimi posted:I spent about 30+ minutes on the internet and did a few searches in the cavern here for figuring out my attempt to find/replace with regex matching and using the found pattern in the replacement to create links to other files. The only matches / replacements I need are the beginning of the line in an html table page, so I should be able to anchor with ^. For the record, parsing HTML with regexes is not recommended. Something like the HTML Agility Pack would make your life much easier.
|
# ? Nov 18, 2013 22:59 |
|
Ithaqua posted:For the record, parsing HTML with regexes is not recommended. Something like the HTML Agility Pack would make your life much easier. Oh, I didn't know I was asking about something that cannot be done that easily. I figured I just don't know the syntax at all. I've outlined all the cases and the structure is guaranteed. I'd really rather not have to install anything. Should I be making a match function and then do the replacing in a for-each loop? Thanks again.
|
# ? Nov 18, 2013 23:51 |
|
So I just started this program to become an IT-technician (Rough swedish translation) and completely new for this year is that we get to learn Powershell! I've never done something like this before and am really confused about how to write a script with parameters that might or might not be used in the syntax. My assignment is to write a script that makes a backup of a directory. The first two parameters are the source and the destination. Destination is optional to write, if it isnt specified the copy will be placed in a default directory, say C:\Backup in this case. The third parameter that might be used is if the copy will be reclusive or not, and the fourth is to specify what files to copy from the source using wildcards. Pseudocode looks something like this: Backup.ps1 $Source $Destination $Reclusive? $Specifics? My problem is how I make Powershell not confuse one parameter for another if one is left out. Like if I wrote $Reclusive and $Specifics but left out $Destination.
|
# ? Nov 20, 2013 12:57 |
|
Frag Man posted:Pseudocode looks something like this: Backup.ps1 $Source $Destination $Reclusive? $Specifics? And I think you mean recursive not reclusive - but maybe you do — I know some /dev/null files that never go anywhere.
|
# ? Nov 21, 2013 00:27 |
|
Thanks for the tip! If I understand correctly, I can disable positional parameters but then I have to write out each parameter in the syntax If I want another value. I think this will work for my assignment. To clarify, the $Recurse (Formerly $Reclusive, my bad) parameter is supposed to tell powershell if the backup is done with subfolders and the whole subdirectory with files, or only the files from the folder specified is copied. The $Specifics is more of a filter that I can specify to only take backups of certain kind of files using wildcards. Example: PS C:\. backup.ps1 C:\folder\ C:\Backup\ -recurse Yes -specifics *.txt Would copy all the .txt-files and the subfolders from C:\Folder\ to c:\Backup\. That's at least what it's supposed to do. I'm currently using If-operators to specify what parameter-values that change the outcome of the script, but that's kinda cumbersome and I feel like there should be an easier way.
|
# ? Nov 21, 2013 14:15 |
|
It may be against the spirit of the assignment, but you can just take those parameters and pass them over to robocopy to avoid reinventing the wheel.
|
# ? Nov 21, 2013 18:31 |
|
Frag Man posted:Example: PS C:\. backup.ps1 C:\folder\ C:\Backup\ -recurse Yes -specifics *.txt A small thing, but you can make $Recurse a [switch] parameter, which is True if -Recurse is present and false if it isn't.
|
# ? Nov 21, 2013 18:40 |
|
AreWeDrunkYet posted:It may be against the spirit of the assignment, but you can just take those parameters and pass them over to robocopy to avoid reinventing the wheel. That's exactly what we aren't allowed to do. Our teacher has several times stated that some methods arent allowed, such as robocopy or using arraylists. Usually after some students have spent several hours writing functions using those methods. If someone could clarify why some methods wouldnt be allowed I'd be vary happy, cause our teacher sure as hell won't. The script is taking form, but we have an unfortunate kink to iron out. Our script is taking backups of the directory, but the backups have different form depending on if they are recursive or not. When the copy is recursive the sourcefolder is fully copied into the folder named BACKUP_$Getdate. But when we arent using a recursive copy-item the folder is not copied, instead the files in the source directory are dropped in the BACKUP_$Getdate directory. I'm not quite sure which form of directory structure is correct for the assignment, but I think it's either way as long as the result of running the script is consistent. I'll just post the script here if that's okay. It's not complete, we still need to add several things. Backupscript posted:
Edit: Mixing up reclusive and recursive AGAIN! Frag Man fucked around with this message at 13:56 on Nov 22, 2013 |
# ? Nov 22, 2013 09:58 |
|
A few things:
The specific problem you're having is because when you do, for example: copy-item C:\Foo C:\Bar", you're telling PowerShell to copy the ENTIRE "C:\Foo" folder into "C:\Bar", so the resulting folder structure is "C:\Bar\Foo". If you do copy-item C:\Foo\* C:\Bar", it'll copy the contents of C:\foo.
|
# ? Nov 22, 2013 15:29 |
|
Djimi posted:And I think you mean recursive not reclusive - but maybe you do — I know some /dev/null files that never go anywhere. I hate seeing mixups like this because they always seem get stuck in my head and I want to use them. A few years ago a co-worker had used 'enchanted' in place of 'enhanced.' For the rest of my life I'll probably have a nagging urge to use the phrase "enchanted mode."
|
# ? Nov 22, 2013 19:57 |
|
PowerShell automagically does things.
|
# ? Nov 22, 2013 20:00 |
|
Frag Man posted:That's exactly what we aren't allowed to do. Our teacher has several times stated that some methods arent allowed, such as robocopy or using arraylists. Usually after some students have spent several hours writing functions using those methods. If someone could clarify why some methods wouldnt be allowed I'd be vary happy, cause our teacher sure as hell won't. Robocopy isn't a method, it's a separate Windows program, and it already does everything the assignment is asking you to do (and then some). It was more of a joke suggestion, since you wouldn't really be learning or doing anything - just accepting parameters and passing them on in the order/format robocopy requires. Not sure why you shouldn't use an arraylist, but I also don't really see how it would help. Maybe to prevent you from going in an unnecessary direction?
|
# ? Nov 22, 2013 20:13 |
|
I'm pulling a telephone number from AD and trying to convert it to a string, so I can use substring to get the last three numbers.code:
Edit - Solved it already. $number = get-aduser -Identity username -properties telephonenumber | select -expandproperty telephonenumber Swink fucked around with this message at 23:35 on Nov 26, 2013 |
# ? Nov 26, 2013 23:06 |
|
Ugh, I need help with a script. Quite simply, I am trying to output a list of users who are in one group, yet not in another. I can do Get-ADUser -Filter {(memberof -ne "group name 1")} and it will output AD accounts which are not in that group. I then tried Get-ADUser -Filter {((memberof -ne "Group name 1") -AND (memberof -eq "group name 2"))} and it does not output anything. In fact the -eq switch does not seem to work, if I run with just that I see nothing. Is there anyway to do what I am trying to do? I have been banging my head against this for a couple of hours and the above it the closest I have got.
|
# ? Nov 29, 2013 12:41 |
|
Dravs posted:Ugh, I need help with a script. I'd honestly use a LDAP query here.
|
# ? Nov 29, 2013 15:01 |
|
My powershell knowledge is almost non-existent so I am picking this up as I go along. How do you do an LDAP query?
|
# ? Nov 29, 2013 15:12 |
|
Dravs posted:My powershell knowledge is almost non-existent so I am picking this up as I go along. How do you do an LDAP query? http://forums.somethingawful.com/showthread.php?action=showpost&postid=374711474 See adaz's post there, instead of the filter being userworkstations, you'd want a (memberof=CN=Group,OU=Users,DC=Domain,DC=com) plus a !(memberof=CN=Group,OU=Users,DC=Domain,DC=com) to NOT out the membership of that other group. You'll want to get the CNs for your two groups. I'm doing this from a phone, sorry for being brief.
|
# ? Nov 29, 2013 15:28 |
|
Hi guys, I'm slowly working my through CBT Nuggets intro to Powershell so forgive any ignorance on my part. I'm trying to build a script that prompts for a username and once it has does three things: 1. Changes the description to "Terminated - $DATE" in the format YYYY.MM.DD 2. Moves the object to a particular OU 3. Strips the object of all group memberships I've got the commands for the steps 1 and 2, except for adding the date in automatically, I'll need help there - but stripping the object is a bit of a mystery at this point. Any pointers will be much appreciated. code:
|
# ? Dec 9, 2013 01:57 |
|
You're looking for something likecode:
|
# ? Dec 9, 2013 07:43 |
|
Here's the finished product:code:
|
# ? Dec 11, 2013 04:59 |
|
Hey guys, I'm a fairly new scripter, been teaching myself PoSh for a few weeks or so at this point. I got voluntold for a project that I now feel may have been a bit above my paygrade and have now spent waaaaaay too long trying to get this to work. The goal: to take an input CSV file and re-create all the directories with the necessary NTFS rights, as well as a network share with permissions. My (main) problem: As far as I know, the script works great up until the part where it has to actually set the share permissions; all the technet articles and resources I've looked up haven't helped me figure out what I'm doing wrong, probably because I'm too inexperienced to recognize where the problem is. Oh yeah and another really stupid loving oversight I didn't think about until today; I've been testing this locally and apparently I have PoSh v3, and the server has PoSh v2. I'm about to test it there and see what errors I get. I might be new to IT in general but I'm pretty certain that ^^THAT^^ was loving dumb. And I know I have a LOT of other problems in my code; all input is welcome but mainly I just wanna get my script to work. Code: http://pastebin.com/FVPkAmQL sample csv: http://pastebin.com/3nCdWSk3 Being that this is the first time I've asked for help like this I'm also pretty sure I'm leaving out a bunch of crucial info; I'll be here all day tho. Thanks in advance for any help, also for this thread! It's been a great resource. EDIT: Oh yeah there's a LOT of probably-hilarious bullshit in there from me trying to track what variables were carrying where and when and other debugging things, just warning y'all Son of Thunderbeast fucked around with this message at 00:33 on Dec 31, 2013 |
# ? Dec 31, 2013 00:30 |
|
Well, what are the errors you're getting?
|
# ? Dec 31, 2013 09:20 |
|
|
# ? May 21, 2024 12:30 |
|
Son of Thunderbeast posted:Oh yeah and another really stupid loving oversight I didn't think about until today; I've been testing this locally and apparently I have PoSh v3, and the server has PoSh v2. I'm about to test it there and see what errors I get. First thing I would do is upgrade the server to v3, if possible.
|
# ? Jan 8, 2014 21:42 |