|
intellisense to the IDE? oh my god yes, yes yessssssssssssssssssssss
|
# ? Mar 22, 2012 21:14 |
|
|
# ? May 21, 2024 17:22 |
|
Start out by saying I'm still absolutely a PowerShell novice, still learning a lot of the basics. So feel free to laugh at me if I have something horribly wrong. Part of my work study is packaging software for silent deployment and I'm trying to start using PowerShell to do it. I'm mostly having success but trying to deploy it with SCCM 2012 gives me an error when the script gets run. I wanted to have someone who knows what they are doing look at my simple PowerShell script to make sure I don't have it screwed up before I dig too deep into seeing if it's a SCCM issue and not just my poor PowerShell knowlege. In this case it's just simply copying some files over and copying some shortcuts, nothing to run. My next step is to also learn how to use the equivalents in PowerShell to stuff that I'm used to using in batch files instead of my messy Get-Location stuff. (Like %SYSTEMDRIVE%, ~dp0% etc...) code:
|
# ? Mar 26, 2012 18:18 |
|
There's nothing wrong with the syntax that I can see, assuming the path and location actually exist. Based on the error you're getting it almost seems as though there might be a directory or file or something that has a character that needs to be escaped out. You could also be missing a " omewhere in the script is the other common time you'll get that error. You are sure get-location is returning the correct value when SCCM runs the script, not some crazy weird temps systemdir when it executes the script? I mean you can add some quick logging like the example below to verify.code:
adaz fucked around with this message at 18:39 on Mar 26, 2012 |
# ? Mar 26, 2012 18:32 |
|
Thrawn200 posted:I get an error saying that "The term 'C:\whatever\$path\is' is not recognized as the name of a cmdlet, function, script file, or operable program." Is this a typo on your part, or is that actually in the error message? adaz posted:Also the equivalents to most of that stuff you're talking about in batch files can be found by doing a cd ENV: and then a dir, just as a quick and easy reference although there are plenty more. So ENV:SystemDrive is the system dir. Neat, I didn't know you could do this. Have a technet link or something for some further reading?
|
# ? Mar 27, 2012 01:28 |
|
Get-Help about_environment_variables is a decent overview, but - as as always - the hey scripting guy article(s) are better for practical examples. http://blogs.technet.com/search/searchresults.aspx?q=environment%20variables§ions=7618
|
# ? Mar 27, 2012 05:55 |
|
PowerShell gurus... I have a simple task that I can't quite get to work. So I want to delete a network folder and all files/sub-dirs. Occasionally this will give me errors, whether it be permissions or path too long. That's fine -- I will just rename the top-level folder and deal with it separately. I tried to "catch" the errors but when I run this sample it just pukes all the errors and never executes the code in the catch block. Am I doing something wrong? code:
|
# ? Mar 27, 2012 17:23 |
|
Catch only catches terminating errors, non-terminating errors won't ever be caught by the catch block by default. Iff the cmdlet itself handles terminating errors, which quite a few do including remove-item, it won't pass them to the try/catch block unless you change how the cmdlet handles errors via it's -errorAction or whatever parameter. So, documentation wise see about_try_catch_finally: http://technet.microsoft.com/en-us/library/dd315350.aspx You can also globally set the $erroractionpreference to "stop", that will make every error on everything terminating... with some rare exceptions mainly contained in the COM interface that hopefully you never run into. adaz fucked around with this message at 17:45 on Mar 27, 2012 |
# ? Mar 27, 2012 17:42 |
|
adaz posted:Catch only catches terminating errors, non-terminating errors won't ever be caught by the catch block by default. Thanks for the help -- clears everything up. I added "-ErrorAction stop" to my Remove-Item statement and I'm good to go.
|
# ? Mar 27, 2012 18:05 |
|
Alright guys I'm back- I feel stupid because every time I write a script that needs to use some real programming concepts- like not just using built in cmdlets to add features to a server or moving users around in AD, I get in over my head. I suppose this is all part of the learning experience here. Let me explain what I need to accomplish- When a user logs into my server, I need to check what group they are in, and according to the group they are in, I need to modify a .url shortcut on their desktop to point to a different location. There is a template .url shortcut in allusers/desktop to reference. After a bunch of google-fu, it seems like in order to do this I need to utilize a WshShell Object, as Powershell doesn't seem to be able to do this natively. I've pieced together and modified some code examples from various blogs, but I don't even know if my if-else if structure is the correct way to do things programatically. Mostly I just need a sanity check and perhaps someone knows a cleaner way to do this. code:
|
# ? Mar 28, 2012 23:24 |
|
This seems to be in the wrong order:code:
|
# ? Mar 29, 2012 07:54 |
|
I think you're trying to achieve the same end result as this.code:
|
# ? Mar 29, 2012 08:20 |
|
Mully Clown posted:I think you're trying to achieve the same end result as this. Yeah this is an exercise in futility. I just made a simpler script to copy the shortcut from a network location applied as a logon script at the group OU level in GP. This actually works and is much easier. Edit: sometimes you just think "this is maybe a cool way to get better at powershell" but man what a waste of an hour
|
# ? Mar 29, 2012 15:35 |
|
Dreadite posted:I just made a simpler script to copy the shortcut from a network location applied as a logon script at the group OU level in GP. Since 2008 you can add shortcuts directly through Group Policy Preferences. And you can put it all in one policy and have it select the right one through Item Level Targeting. Anyway, don't discount your hour fiddling with this, practice with powershell is always valuable! Even when it won't pan out. Part of the process is knowing when you should or shouldn't use PS.
|
# ? Mar 29, 2012 15:48 |
|
I need some help with NTFS AD permissions. (I refuse to go back to ICACLS. ) I've got a script that makes a folder. I now want to set an AD user account to have full control to that folder, all subfolders, and files. The problem I'm running into is that these permissions are only set for "This folder only" and aren't being inherited. So I know that I need to specify inheritance settings as well. I'm just wondering how to go about it. I can't seem to find anywhere on MSDN how these methods want their input (quite possible I just don't know how to look things up properly on MSDN.) Here's what I have currently, which produces the folder with permissions only to the folder and nothing else: code:
code:
Side question: Do I want to be using the $Acl.AddAccessRule method or $Acl.SetAccessRule method? Does it matter? Does using "Set" override existing rules on the ACL object? That was my assumption since "Add" just seems to append the rule to the existing rules. e: vvv Thanks man! I'll give this a shot right now. Also, it looks like we weren't the only ones upset with MS's veiled inheritance rules (check the bottom post haha.) Siets fucked around with this message at 21:09 on Mar 29, 2012 |
# ? Mar 29, 2012 20:38 |
|
Hey whoa, I get to be helpful here. Siets, look at my last few posts in this thread, I was dealing with the exact same thing. You need to set your propagation and inheritance flags properly. http://forums.somethingawful.com/showthread.php?threadid=3286440&userid=0&perpage=40&pagenumber=11#post401783499 edit: I think this was the page that pointed me in the right direction. http://developers.de/blogs/damir_dobric/archive/2007/06/18/directory-security-and-access-rules.aspx Dreadite fucked around with this message at 20:56 on Mar 29, 2012 |
# ? Mar 29, 2012 20:54 |
|
adaz posted:To get started what I'd use is a function I wrote long ago and my normal method of avoiding export-CSV's... eccentricities. Yes it would be a glorious world where we could just pipe the DataSet to export-csv and it'd handle it gracefully... unfortunately that world doesn't exist. Sorry to quote from so far back, but good lord you are not kidding about this cmdlet. I have a multi-line comma-delimited string, you stupid piece of poo poo! Why won't you let me just pipe it straight in!
|
# ? Mar 31, 2012 04:40 |
|
stubblyhead posted:Sorry to quote from so far back, but good lord you are not kidding about this cmdlet. I have a multi-line comma-delimited string, you stupid piece of poo poo! Why won't you let me just pipe it straight in! If it is already comma delimited, just pipe it to a text file with .csv as its extension.
|
# ? Mar 31, 2012 07:55 |
|
Jelmylicious posted:If it is already comma delimited, just pipe it to a text file with .csv as its extension. welp guess that would have worked too. I figured out a lot of poo poo in the process of getting this to work though, so it wasn't a total wash.
|
# ? Mar 31, 2012 09:22 |
|
Jelmylicious posted:If it is already comma delimited, just pipe it to a text file with .csv as its extension. This might or might not work depending on the encoding parameters and the parser, I've had issues with it before. IN general I find it easier to use the creating your own object approach. But yeah, export-csv
|
# ? Mar 31, 2012 22:33 |
|
adaz posted:This might or might not work depending on the encoding parameters and the parser, I've had issues with it before. IN general I find it easier to use the creating your own object approach. Yeah the comments in your code from a few pages back were really helpful. I was using a script one of my colleagues wrote as a template, and he did it in basically the same way. He didn't comment his code though, so I had no idea what he was doing and subsequently left out some pretty important stuff in my own script.
|
# ? Apr 1, 2012 02:06 |
|
Hey there 'Shellers (need a better name for PS enthusiasts), for once I'm not coming here with a naked cry for help. Instead this is more of an opinion question. I'm automating some FTP scripts and I'm tired of doing it in batch files so I'm going to PowerShell it. I'm probably going to do this (first answer): http://stackoverflow.com/questions/1867385/upload-files-with-ftp-using-powershell But thought I'd check in with you guys to see if there's a cooler way. Right now it's going to be one file (since it's always known and doesn't change) so I don't need to worry about for each or anything like that. One question I did have, if I needed to extend this to SFTP/FTPS is it actually just as easy as changing the WebRequest.Methods+xxx call?
|
# ? Apr 5, 2012 03:42 |
|
Stupid question time again, regarding the following scriptcode:
code:
code:
code:
|
# ? Apr 7, 2012 00:47 |
|
Nebulis01 posted:Stupid question time again, regarding the following script Bit of a late reply, but the first error you're running into is the good ole NTFS(?) limitation on path length, which can not exceed ~250 characters. It may also be causing takeown not to work properly which would then account for the two other errors. You could for example, create temporary file shares in a subdirectory of the path (one at the 2012-04-01 directory in your example case might be good) and do the file removal in those which bypasses the issue. Quick example of that: code:
Nebulis01 posted:I tried to end run around Remove-Item by creating the variable $olddata and passing that to the a command prompt invoking RD(rmdir), but that also errors out I believe Invoke-Expression will try to run the powershell version of the command, if it exists, so if you want to run the command prompt version of rmdir, you'd want to do something like this: code:
|
# ? Apr 11, 2012 07:51 |
|
I don't suppose anyone has used powershell to bulk migrate user accounts across domains? Ideally keeping all of their properties (profile paths, homedrives etc?) Is exporting to csv and reimporting on the new domain the best way to do this?
|
# ? Apr 11, 2012 19:12 |
|
Honey Im Homme posted:I don't suppose anyone has used powershell to bulk migrate user accounts across domains? Ideally keeping all of their properties (profile paths, homedrives etc?) I have actually, but not with all the attributes intact, and not in a way that would help you that much. We mirror our AD environment into a SQL db to take the load off the DCs for data queries and the like, so I used SQl to pull in the data. What you would do, conceptually, to pull an entire OU across would be something like this. code:
1.) You can't put in passwords obviously they will be encrypted and hashed. Will need to set a default password. 2.) Various fields (proxy address is a good one) will need to be iterated through and added, they probably won't straight set just by doing a put 3.) Will need to add a filter when going through the properties (Switch would be great for this) to skip adding things like CN, DistinguishedName,badpasswordtime,logoncount,adspath,logontimestamp or any other read only field in AD. You could also filter that out in the Searcher by only returning the things you care about like so code:
adaz fucked around with this message at 22:52 on Apr 11, 2012 |
# ? Apr 11, 2012 20:45 |
|
Thank you so much. Will have a play around and see how things go.
|
# ? Apr 11, 2012 21:50 |
|
kampy posted:stuff Hey thanks for this, i actually just now have a change to look at this script again so good timing. I'll see how it works and report back.
|
# ? Apr 11, 2012 22:23 |
|
Nebulis01 posted:Hey thanks for this, i actually just now have a change to look at this script again so good timing. I'll see how it works and report back. Alrighty, well I ended up not getting it to work the way I wanted. I used ntbackup to create a .bkf of the flatfile stuff that needed to be archived and just had ps move that over, it works out pretty well and deletes when it's supposed to.
|
# ? Apr 18, 2012 18:05 |
|
I have a quick question, I am using the following in order to create a last written file output, however I want to format the date in UNIX time (e.g. UFormat %s) - any help or direction would be great. Do I need to go down the object route? > Get-ChildItem c:\ -recurse | Select-Object FullName, LastWriteTime, length
|
# ? Apr 23, 2012 17:15 |
|
NaughtyHusky posted:I have a quick question, I am using the following in order to create a last written file output, however I want to format the date in UNIX time (e.g. UFormat %s) - any help or direction would be great. Do I need to go down the object route? This should work: code:
code:
|
# ? Apr 23, 2012 18:28 |
|
Here is the function you'll need the question is do you want to make it all pretty with the pipeline input or are you actually exporting this stuff out to CSV or something?code:
|
# ? Apr 23, 2012 18:45 |
|
Just got into PS 2.0 recently and I quickly learned two things: - Exporting to CSVs is awesome (especially for a major project I'm working on to audit my company's AD forest and control security in the future). By extension, piping in general is awesome for stuff like using the output of one command as the input to another command. - Get the Quest command suite; everyone uses it anyway (thank you Powershell in Practice). Also, dunno if anyone else has seen this but the Powershell 2.0 Administrator's Pocket Consultant is available on the Google Play store for only $2.99. It was nice to have a searchable reference always at hand on my phone.
|
# ? Apr 24, 2012 15:12 |
|
adaz posted:Here is the function you'll need Jelmylicious posted:This should work Great stuff, thanks to both of you, and yes I plan to pipe this out to CSV.
|
# ? Apr 24, 2012 21:02 |
|
Ive run into a small issue. I had to restore network drives from a backup, but ownership and security permissions are not restored. So, now im stuck with 1200 folders that have incorrect ownership and will not be mapped when a user logs in until they have ownership of that folder. I want to make sure what im thinking makes sense and check to see if there is possibly an easier way to do this. The folders are their user names. Could I create an array of the names, then use that to assign ownership of the proper folder? Or can I do a for each, read the name then assign that ownership without the array? I'm way to inexperienced at this.
|
# ? May 2, 2012 15:04 |
|
Drumstick posted:The folders are their user names. Could I create an array of the names, then use that to assign ownership of the proper folder? Or can I do a for each, read the name then assign that ownership without the array? I'm way to inexperienced at this. Yes, Basically you read Foldername, get the user from AD and use Set-ACL to set the new permissions. Be careful not to lock yourself out by overwriting admin permissions. I'll see if I can get you some code.
|
# ? May 2, 2012 15:09 |
|
Fantastic, thank you so much. Im glad i'm at least on the right track. I didnt even consider the possibility of locking myself... Im glad I didnt just wing it.
|
# ? May 2, 2012 15:11 |
|
Drumstick posted:Fantastic, thank you so much. Im glad i'm at least on the right track. I didnt even consider the possibility of locking myself... Im glad I didnt just wing it. Couldn't fully test, since I am away from my domain right now. This should work. Shouldn't have to tell you, but try it on a testfolder first: code:
|
# ? May 2, 2012 15:37 |
|
It works! Thank you so much! I was wrong. It mostly works. I tired running it on multiple folders and its assigning multiple people to it instead of just the one the folder is named after, and folders/files inside are not inheriting. It looks like some other people in the thread recently had the same issue Drumstick fucked around with this message at 16:39 on May 2, 2012 |
# ? May 2, 2012 16:07 |
|
You need to set inheritance and propagation flags when you create your new access rule. See http://msdn.microsoft.com/en-us/library/ms147785.aspx for the technical writeup but here is a good article explaining it in more general terms: http://camillelemouellic.blog.com/2011/07/22/powershell-security-descriptors-inheritance-and-propagation-flag-possibilities/ So for what you want to do you need to set inheritanceflags of ContainerInherit and ObjectInherit and propogation flags to none. something like this code:
|
# ? May 2, 2012 18:36 |
|
|
# ? May 21, 2024 17:22 |
|
Fantastic! Thank you everyone for the help. I really appreciate it, and I know my users will too. This is new territory for me and Ive always received great help and advice from these forums.
|
# ? May 2, 2012 18:50 |