|
What are everyone's opinions on the Quest AD Cmdlets? Link I know you can just use .NET to access directory services, but for some of the projects I've been building I find it amazing for user manipulation. I wrote a script recently to query AD and check password expiration dates, and then send custom emails based on certain thresholds for remote users who basically just check webmail, and output HTML reports (which management loves). I've gone all in on Posh unless it really is just much easier doing a task with the standard CLI, but this is rare. I got a script request that I'm pretty sure is uncharted territory and wondering if anyone has ideas. Google and MSDN have nothing. Essentially one of our engineers lost a user's offline cache during a server migration this weekend, so they want me to make a script that will auto-extract data in said cache to a temp location just to play it safe. Now in WinXP this is easy: just use the CSCCMD utility. But in Vista/7, these tools simply don't work. The only other option seems to be using the WMI provider for Offline Files or call the API directly. I am by no means an expert coder but I have dabbled in PHP/Perl and SQL, this may be above my skill level. I essentially want to know if I can enumerate the offline file listing and then build the code to extract said files from the CSC database to another folder, in case this is an issue down the line. The WMI providers, etc can be found here. But reading through it just seems to show me how to list but not necessarily manipulate the files in there. Anyone got any ideas or breadcrumbs on where I should go with this?
|
# ¿ Nov 10, 2010 17:21 |
|
|
# ¿ May 2, 2024 11:16 |
|
You're probably better off not doing it via the registry (which I find really cumbersome in PShell) and just use WMI.code:
code:
That should do it. Documentation on the method is here in case you are curious. Seems like this method isn't supported in Windows 2003 but nothing about XP. I would definitely test the method on a VM first, the status codes are in that document too so you can see if it worked or not. Also if you're ever curious about what methods are available to you, just pipe your object/command to: code:
Hope this helps!
|
# ¿ Mar 9, 2011 08:33 |
|
Rabid Snake posted:Is there an easy way to send an email to a email alias when a script throws an error? We're using Office 365 to handle our exchange server so the SMTPclient class won't work for us. We've tried to use outlook but it throws security errors. Anyone have experience with using outlook to send an email with a log attachment file when the script throws an error? You should be able to use Send-MailMessage if you're using PS 2.0, and pass the $error variable to the body. http://technet.microsoft.com/en-us/library/dd347693.aspx I abuse the hell out of it for custom reporting, it's pretty flexible just make sure you process all your objects to formatted strings before attempting to send or it will just look like garbage.
|
# ¿ Aug 3, 2011 05:56 |
|
Pipe it to Select-Object for conversion to a CSV format:code:
Format-List is really for display purposes or pure string output. So alternatively you can do this: code:
|
# ¿ Aug 4, 2011 18:30 |
|
You'll laugh it's so easy, but there are a few gotchas:code:
The key part here is the $_, which represents the current index within the array of items in $updates (the list of files, basically) that it iterates through. Also, by default PS will not run commandline strings as is, so that's why you use Invoke-Expression to execute the commands. Note the single quotes inside the double, without them it will treat spaces as multiple lines which you don't want. And how to do the whole thing in one line using aliases and no need for file outputs: code:
|
# ¿ Aug 9, 2011 23:58 |
|
I'm thinking this is due to how Powershell handles items by default based on their type. The type on that query is a ManagementObject, and not a System.Array type, which I think would give you the expected results. I also tried it in 2008, but didn't get a count on a single return, I guess it just implies 1 when it doesn't return a result. That is pretty dumb. So if you wanted to get a legitimate count, you could make a dummy variable and run the object through a quickie loop like so: code:
|
# ¿ Sep 27, 2011 17:28 |
|
|
# ¿ May 2, 2024 11:16 |
|
Version 2 also has the very easy to work with Send-MailMessage built in, and if you have .NET 4.0 you gain a lot of additional capabilities on top of that.
|
# ¿ Dec 3, 2011 01:43 |