|
Dr. Arbitrary posted:I think there's a toolmaking in a month of lunches book that might be up your alley. Yup, just found it. I'm gonna go with that one since anything I can't figure out I have the internet for. I don't need a reference book, I need practical exercises. Thanks!
|
# ? Sep 9, 2014 18:22 |
|
|
# ? May 9, 2024 23:47 |
|
lol @ powershell docshttp://technet.microsoft.com/en-us/library/ee176910.aspx posted:You know how it is: as soon as you have everything set up just perfect, you’ll invariably want (or need) to change things. The files you put in the C:\Scripts folder? Turns out they should really be in C:\Test. Or maybe just the .zip files should be in C:\Test. Or maybe - well, you get the idea. Can you use Windows PowerShell to move items from one location or another? Let’s put it this way: if you couldn’t, it would be pretty silly to have a cmdlet named Move-Item. It's buzzfeed writes technical documentation.
|
# ? Sep 10, 2014 15:50 |
|
I'm using Invoke-Webrequest in a while($true) loop in order to obtain information from a web server. The protocol is that you keep listening until you get information, and then start another request. The problem is, in the middle of this loop - but in the same script, I need to be able to send requests to it. Is this possible with PS?
|
# ? Sep 12, 2014 19:00 |
|
Fruit Smoothies posted:I'm using Invoke-Webrequest in a while($true) loop in order to obtain information from a web server. The protocol is that you keep listening until you get information, and then start another request. The problem is, in the middle of this loop - but in the same script, I need to be able to send requests to it. Is this possible with PS? Use background jobs! code:
|
# ? Sep 12, 2014 19:11 |
|
CLAM DOWN posted:Use background jobs! Thanks, but I need a way of having the output from the background added to the same console as the input. Doesn't look like this is possible, sadly.
|
# ? Sep 12, 2014 19:47 |
|
Dren posted:To see the members of the com object. Is there any way I can get more detailed help about that com object and it's members? What about a list of all the com objects that are available? quote:Thanks, but I need a way of having the output from the background added to the same console as the input. Doesn't look like this is possible, sadly. code:
|
# ? Sep 15, 2014 07:02 |
|
I posted this in the server thread, but figured it would probably be more at home here. Need some ideas... Environment: Multiple 2008 R2 and 2012 file servers User has a mapped "home drive" to a share on their site's server, each share size is limited via quota management. This "home drive" is synced via offline files. There is a fun quirk where the sync partnership breaks once a user hits ~100% of their quota... I want an automated way to identify users that are above 95% of their quota & their share has not been modified in > 2 weeks. This would help identify users whose local files are not being synced to the servers. Is this possible? I'm powershell illiterate, but seems like something that can be done.
|
# ? Sep 16, 2014 20:31 |
|
I'm sure it can be done in powershell, but have you looked at the File Server Resource Management tool? You can setup quite a few alerts to be emailed in there. I haven't looked recently, but might want to check that out before spending time on making powershell do it.
|
# ? Sep 16, 2014 20:57 |
|
I can set up alerts for users at a certain % of their quota, but I need a way to single out people from that list who have not modified their share in > 2 weeks. I can't find a way to do that with the canned alerts/reports in Server Resource Manager
|
# ? Sep 18, 2014 16:54 |
|
Hey guys, I have to transfer a large number (>15,000,000) of small files totaling about 2TB from a 2003 to 2008 R2 server, maintaining folder structure and NTFS ACLs. Should I stick with robocopy, or would Copy-Item suit me fine here?
|
# ? Sep 18, 2014 19:17 |
Robocopy with its multi threading and retries and so on is pretty drat good for this sort of automation. It's tried and true for me. Not sure if copy item is as robust. I've always just used robocopy.
|
|
# ? Sep 18, 2014 19:28 |
|
Just /MIR it and log to a file.
|
# ? Sep 18, 2014 19:52 |
|
CLAM DOWN posted:Hey guys, I have to transfer a large number (>15,000,000) of small files totaling about 2TB from a 2003 to 2008 R2 server, maintaining folder structure and NTFS ACLs. Should I stick with robocopy, or would Copy-Item suit me fine here? Not powershell necessarily but doesn't winrar preserve permissions? Sounds like it'd be easier to copy one big file than lots of little ones.
|
# ? Sep 18, 2014 21:46 |
|
Scaramouche posted:Not powershell necessarily but doesn't winrar preserve permissions? Sounds like it'd be easier to copy one big file than lots of little ones. The gains in copy/write time probably don't outweigh the time it would take to compress/decompress. I don't know, kinda talking out of my rear end... but something to consider.
|
# ? Sep 19, 2014 02:59 |
|
Spazz posted:Any suggestions on a book for someone who has PS experience but wants to round out their knowledge? I've been writing scripts for about 9~ months now, with past Python experience, but I know I'm missing some stuff. I would just get the Payette book (PowerShell in Action I think).
|
# ? Sep 20, 2014 03:10 |
|
CLAM DOWN posted:Hey guys, I have to transfer a large number (>15,000,000) of small files totaling about 2TB from a 2003 to 2008 R2 server, maintaining folder structure and NTFS ACLs. Should I stick with robocopy, or would Copy-Item suit me fine here? I was involved in a similiar situation where I re-wrote part of our NAnt deployment scripts into Powershell in an attempt to cut down the superfluous copying of around 80,000 files of varying sizes. NAnt was doing it in about 2, maybe 2.5 hours. The script I wrote generated filehashes and stored them in a file on the destination, pre-deployment. It then did a simple -neq check on each file, running locally at the destination, and copied a file over from staging if the hashes didn't match. I cut the deployment time for 80,000 files + 80,000 changes down to about 20 minutes, which was a pretty huge improvement! Robocopy just copied all 80,000 files over in about 8 minutes, which beat my best-case scenario of "no changes" by about 2 minutes. There was really no point in trying to do a diff and only copying changes if Robocopy could just copy the entire drat thing in less time. So yeah probably just use robocopy. It might be out of your control but you may also want to reconsider having 2TB of data on a win server machine instead of a SAN or something.
|
# ? Sep 20, 2014 08:01 |
|
So this might not be a specifically Powershell thing, but: I've created a script that does a bunch of stuff to deprov a user account. Disables it, strips all the groups, moves it to a holding OU for eventual deletion, etc. When I run it from my desktop machine, it works great. No problems at all. When I copy the script to the server(2k12r2 DC) and tried to set it up as a scheduled task, it gives all Access Denied errors. Even if I try to run it from a command prompt, same thing, Access Denied errors. Tried running as admin and I've run it as a Domain Admin account. What's different about these two environments that keeps it from flying?
|
# ? Sep 22, 2014 23:26 |
AlternateAccount posted:So this might not be a specifically Powershell thing, but: Is this a Set-ExecutionPolicy thing, perhaps? Get-Help Set-ExecutionPolicy Basically, by default, powershell won't run scripts that are from another system.
|
|
# ? Sep 22, 2014 23:32 |
|
Couldn't give us a look at that script could you?
|
# ? Sep 23, 2014 02:49 |
|
ConfusedUs posted:Is this a Set-ExecutionPolicy thing, perhaps? Swink posted:Couldn't give us a look at that script could you? Was this to examine what my issue is or were you wanting to know how I did a particular thing? AlternateAccount fucked around with this message at 15:27 on Sep 23, 2014 |
# ? Sep 23, 2014 14:52 |
|
AlternateAccount posted:
Are you running the same version of Powershell as on the machine where it's working? Are the necessary modules imported?
|
# ? Sep 23, 2014 18:15 |
|
AreWeDrunkYet posted:Are you running the same version of Powershell as on the machine where it's working? Are the necessary modules imported? V4 all around. The only used module is ActiveDirectory, which is being imported successfully. for more info, here's an example of a line that's running that's kicking back an Access Denied on the "Move-ADObject" part: code:
AlternateAccount fucked around with this message at 21:46 on Sep 23, 2014 |
# ? Sep 23, 2014 21:38 |
|
Someone please help. I'm mentally blocked right now. I'm trying to see which "Microsoft Programs" I have installed that match a certain filter and I need their GUID among other things. So far I created a command to get all data matching "Microsoft" and this works perfect: code:
Exclusion.txt contains: code:
code:
I need an export.csv that does all the above and I'm completely stumped. I've tried creating foreach loops etc and I can't get anything working. Can someone write me a snippet please? simcole fucked around with this message at 05:11 on Sep 24, 2014 |
# ? Sep 24, 2014 05:05 |
|
There's no need to do it all as a one-liner. I'd probably use a Test-Any implementation and do it something like:code:
code:
|
# ? Sep 24, 2014 07:03 |
|
AlternateAccount posted:Running the exact same line on my desktop(while subbing an actual user in for the variable) works like a champ. You're logging into the same user on your desktop and on the DC, right? Powershell isn't elevating to admin as DC-MACHINE1\Administrator and then failing because it isn't DOMAIN\YourAccount who is a domain admin? If you're using the same credentials from two different locations there should be no issue. It seems like a problem with the credentials. That being said we have a scheduled task VM and all of our scheduled tasks run under a separate scheduled tasks account. I've never tried to interact with AD from the DC itself. simcole posted:Someone please help. I'm mentally blocked right now. code:
You might need a ForEach-Object loop in there somewhere, and you might be running into problems with -contains and -notcontains being too specific and returning the wrong value. It isn't in your code here but I am assuming you are defining $ExclusionList somewhere? I'm a little confused about the "-notcontains $ExclusionList[0]" part, why do you need the [0]? If you need to exclude more than two or three types of product, I would suggest you format the script something like: code:
|
# ? Sep 24, 2014 07:18 |
|
[quote="Reiz" post="435330113"] There's a lot of stuff going on here. Given the requirements, I would probably do something like: code:
|
# ? Sep 24, 2014 19:58 |
|
brosmike posted:There's no need to do it all as a one-liner. I'd probably use a Test-Any implementation and do it something like: I got it working with your code. I wasn't sure about the ($exclusion in $exclusionList) but it's working. I'm still not sure I quite grasp how that works. Does $exclusion get set to whatever the item is in each line? How is that variable initialized? I prefer the 2nd method personally. Thank you kind sir.
|
# ? Sep 24, 2014 20:11 |
|
Reiz posted:You're logging into the same user on your desktop and on the DC, right? Powershell isn't elevating to admin as DC-MACHINE1\Administrator and then failing because it isn't DOMAIN\YourAccount who is a domain admin? If you're using the same credentials from two different locations there should be no issue. It seems like a problem with the credentials. Well, eventually once I get this working, it will be running under a system account and not mine. I'm logged into the DC as the same account. I've also tried doing it as a "runas:" from a few other accounts, no go. I am completely stuck. edit edit edit: OK, I was wrong, apparently all of the commands DO work when I start Powershell as Administrator. So that mystery is solved. Sorry, I apparently got turned around on that one. Now, when I am trying to run the same script as a scheduled task, I'm testing it using the same account I am logged into the box with an "[ ]Run with the highest privileges" is checked, but it's not appearing to do anything. Is there a trick to getting a script to Run As Admin properly in scheduler? edit edit edit 2: I GOT IT. FINALLY. So when you set up a script in Task Scheduler, you can't just put MYBIGDUMBSCRIPT.PS1 in the box. You have to put POWERSHELL.EXE and then put your script name in the arguments. Always the dumbest poo poo. Thanks for the help, everyone. AlternateAccount fucked around with this message at 21:37 on Sep 24, 2014 |
# ? Sep 24, 2014 20:42 |
|
Yeah task scheduler is a big fuckup in all respects really, paths, quotation marks, permissions, all of it. It's amazing how they tried to duplicate the functionality of chron and make it even more obtuse to use.
|
# ? Sep 24, 2014 23:03 |
|
simcole posted:I got it working with your code. I wasn't sure about the ($exclusion in $exclusionList) but it's working. I'm still not sure I quite grasp how that works. Does $exclusion get set to whatever the item is in each line? How is that variable initialized? Yes, the code:
Note that the foreach statement is not the same thing as the ForEach-Object cmdlet, even though they do similar things and even though you can use "foreach" as an alias for ForEach-Object in normal usage.
|
# ? Sep 25, 2014 05:29 |
|
Fun time saving techniques: % = Foreach-Object, ? = where-object. Use them wisely.
|
# ? Sep 25, 2014 23:05 |
|
^ I hate seeing those in scripts. I never remember which is which.
|
# ? Sep 26, 2014 01:21 |
|
Swink posted:^ I hate seeing those in scripts. I never remember which is which. I remember the where shortcut by the fact it is asking a question... ?
|
# ? Sep 26, 2014 01:52 |
|
Ok, I have a tough last question. I'm retrieving a list of installed software that's made by adobe. I need to see the time it was last run and report it back. If it was never run I need it to say "Never Run". I know how I can do this via gwmi Win32_product but I can't use this method. It will cause the OS to validate every installed product on the machine and bog everything down. I KNOW there is a way to get this from the registry but I don't know where to begin and google isn't being helpful. Can someone point me in the right direction or give me a snippet? Thanks. Ninja edit: I need it to work on x64 x32 etc. I think there's 3 places to look to include all that. Edit2: I hate it when I answer my own questions shortly after I ask, but I'm still partially stuck. Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where -FilterScript {$_.DisplayName -like "*Adobe*"}| Select-Object DisplayName, Publisher But I still can't find the "last run" property anywhere. I need to know if my designers are using the full suites or if we can save money by only buying certain applications. Also I guess 32bit version is just removing the wow6432node. simcole fucked around with this message at 17:57 on Oct 10, 2014 |
# ? Oct 10, 2014 17:26 |
|
ConfusedUs posted:Is this a Set-ExecutionPolicy thing, perhaps? By default PowerShell won't run any scripts, unless my memory is failing me.
|
# ? Oct 11, 2014 04:27 |
|
Does a last run property actually exist? I've always assumed you need 3rd party software to track that kind of thing.
|
# ? Oct 12, 2014 01:34 |
|
Swink posted:Does a last run property actually exist? Its included in the Win32_SoftwareFeature set. I'm not sure if that verify's all the installs too... Can anyone comment on that? http://msdn.microsoft.com/en-us/library/aa394458(v=vs.85).aspx It also doesn't work on XP or Server2003. Was hoping to use a different method. simcole fucked around with this message at 03:14 on Oct 12, 2014 |
# ? Oct 12, 2014 03:08 |
|
Malcolm XML posted:Fun time saving techniques: % = Foreach-Object, ? = where-object. Saves time when writing, makes them a nightmare to debug when you forget which is which. My scripts are full of them
|
# ? Oct 13, 2014 09:38 |
|
As a guy that doesn't have any real practical use for Powershell, I've been having a blast tinkering around and trying to figure out how all these different cmdlets work and what they'd be useful for. Anyone aware of any guided exercises for PS like they have for JavaScript on Code Academy? I don't work with computers professionally (yet!) so I'm really just sitting at home on my couch messing around on my laptop and soaking up what I can on my days off.
|
# ? Oct 13, 2014 14:12 |
|
|
# ? May 9, 2024 23:47 |
|
Edit- Got it!
TheEffect fucked around with this message at 18:23 on Oct 13, 2014 |
# ? Oct 13, 2014 15:21 |