Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Tuesday, March 5, 2019

PowerShell Resources

Since its release waaay back in November of 2006, PowerShell usefulness has continued to grow.

With all the different modules, capabilities and properties, it's hard to keep up with the language. Luckily there are numerous resources available to us.

Since I often use my own blog as a resource, here's a list of sites to keep me and you successful and informed.

Microsoft PowerShell - From the "mothership"

Idera Community - Nice group, lots of info

PowerShell Scripts Blog - A few hundred scripts to choose from

Get-PowerShell - A little crusty, but over one hundred examples

A Taste of PowerShell - Quite crusty, but lots of useful examples

Also don't forget Spiceworks and Experts Exchange for tutorials and problem solving.

Monday, November 10, 2014

Ifconfig: command not found

CentOS, say it isn't so! Having just done the minimal install of CentOS 7 as a VM, I wanted to install VMware tools. I thought I installed all the prerequisites when the script halted at "Setup is unable to find the "ifconfig" program on your machine."

I ended the script and incredulously ran the ifconfig command, thinking it had to be wrong, but it's no longer included. The ip command has now taken over networking duties, but the VMware script didn't care. I ran yum provides ipconfig, but no love: "No package ifconfig available". A couple of web searches later and I found the package I needed to bring it back...

# yum install net-tools

BTW, don't be surprised if Fedora and RHEL (and it's other offspring) are missing ifconfig as well.

Wednesday, February 8, 2012

Hide Your Windows System from the Network

Should you wish to hide your Windows system from the Network Neighborhood just run the command below:

c:\net config server /hidden:yes

There's a bevy of net commands to be used to perform all sorts of tasks; truly worth investigation.

Saturday, January 21, 2012

Activate Windows and Office at the Command Line

I was recently looking for a way to activate Windows 7 and Office 2010 at a command prompt; this is what I found...

Since the release of Vista, you can use the command line utility slmgr for Windows activation when using a MAK (or Multiple Activation Key).

Windows Activation

  1. Open a command window (as administrator)

  2. And run...


slmgr -ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
slmgr -ato

Office Activation

  1. Open a command window (as administrator)

  2. From C:\Program Files\Microsoft Office\Office14 run...


cscript ospp.vbs /inpkey:xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
cscript ospp.vbs /act

Who needs all that pointing and clicking anyway?

Wednesday, December 28, 2011

Freeware Utilities

I'm always looking for more utilities to add to my arsenal for scripting, automating and generally freeing up time for other tasks, like sipping a fresh coffee ;^)

Over the past few months I've been pointed to, or found, four more sites chock full of tasty utilities.

  • AnalogX has a varied collection covering network, system, programming, even audio utilities.

  • joeware has a whole pile of free tools, many related to Active Directory, account management and networking.

  • NirSoft has an impressive array of tools for forensics, networking, systems, passwords and a whole lot more. They also have a blog so you can keep posted on updates and additions.

  • Optimum X has a decent list of network, software and login utilities. Although some are a bit long in the tooth (one is from 9/98), there's still some gold here.


These should keep you busy for at least a few minutes. And as always they're my favorite price, free.

Saturday, December 17, 2011

Search Fails for Some Outlook or OWA Users

Due to a recent power outage at a client site, their Exchange search catalogs became corrupted. The issue at hand was that searches in Outlook or OWA only resulted in showing results prior to the outage.

To confirm that this was the case, I opened the trusty EMS and ran this command on an affected individual.

test-exchangesearch username | fl

This result confirmed the catalog corruption:
ResultFound : False
SearchTime : -1


The fix is rather easy, but depending on your database size, can be rather lengthy. The script below stops the Microsoft Exchange Search Indexer, deletes the Catalog of the database in question and restarts the Indexer which fires off a complete rebuild.

You can find the script here (from where it must be run): <drive>:\Program Files\Microsoft\Exchange Server\Scripts

Syntax: ResetSearchIndex.ps1 -force <database>

Example: ResetSearchIndex.ps1 -force "Mailbox One"

The rebuilding of our catalogs took almost an hour for a 80GB database. And that was on a fairly powerful system with 32GB of RAM.

Tuesday, December 13, 2011

Script to Export a Mailbox to PST

With an occasional need to export a user mailbox to PST for archive, I decided it would be useful to be able to call up a script and save myself some time and mouse clicking.

Should you wish to give the script below a try, copy it into a text file and change the extension to .ps1

Note: This script should be run from a system with Outlook and the Exchange Management Tools installed (they both need to be 32 or 64-bit) for this to work).

rem Gathering names for labeling the exported PST
$fname = Read-Host "First name?"
$lname = Read-Host "Last name?"


rem Assigning the current date to the $date variable
$date = get-date -uformat "%Y_%m_%d"


rem Capturing name of mailbox account (assigning to $uname variable)
$uname = Read-Host "Username?"

rem Capturing admin acct that is currently logged in to add mailbox permissions (assigning to $admin variable)
whoami > $admin

rem Adding permissions for admin allowing export
Add-MailboxPermission -AccessRights FullAccess -Identity $uname -User $admin

rem Exporting mailbox to D:\PSTs (change path to your liking)
Export-Mailbox -Identity $uname -PSTFolderPath D:\PSTs\$fname"_"$lname"_"$date.pst

If at some point I get time or get paid to do so, I'll make a script to allow the use of a list for mass export.

Wednesday, November 23, 2011

Recursively Add Public Folder Permissions

Last week I found myself having to export (for archival) and remove a large tree of Public Folders. I thought the task would be easy, open Outlook, highlight the top level folder and Export to PST.

Little did I know someone changed the top-level permissions of the folder I previously created, removing any admins from the list, so any new folder in the tree inherited the lack of admin rights. Now I had to change permissions on 472 folders, not something to be done individually.

A short search yielded just the info I needed. There is a script called AddUsersToPFRecursive.ps1 in the \Microsoft\Exchange Server\Mailbox\Scripts directory; use and syntax is below.

AddUsersToPFRecursive.ps1 -toppublicfolder \Finance -User "Joe Admin" -Permissions Owner -Confirm:$False

Change the -toppublicfolder to \ or \Marketing\Calendars, whatever suits your needs. And be sure to add the -Confirm:$False switch, otherwise you will have to hit Enter (or Yes) for every folder change. Don't ask me how I know...

Saturday, November 12, 2011

PowerShell: Execution of scripts is disabled

This information is available on many sites, but I'm tired of searching for it every few months when I switch laptops/tablets.

Whenever you try to run an unsigned PowerShell script, you get the following message: "File C:\Custom\Test.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details."

I certainly believe Microsoft is doing the right thing with keeping PowerShell script execution secure with the proliferation of malware and 99%+ of Windows users don't even know about PowerShell.

Changing the PowerShell security setting is a simple affair. Open PowerShell as an Administrator and run the following: Set-ExecutionPolicy

Your choices are:
Restricted (default) - Which stops all unsigned scripts from running.
AllSigned - This allows only signed scripts to run.
RemoteSigned (my recommendation) - Allows local scripts to run, but all downloaded or remotely executed must be signed.
Unrestricted (not recommended) - This allows all scripts to execute, whether from an e-mail, website or instant message.


Syntax: Set-ExecutionPolicy RemoteSigned

Tuesday, November 1, 2011

Setting the Out of Office Reply at the Command Line

If you've ever had to set someone's (like a VP's) Out of Office message because they left town before doing so, and of course don't have access to Outlook Web Access, it can be quite a disruption to your work. Recently I was surfing Jim McBee's blog and found this gem, which he in turn had gotten from Bharat Suneja and the Exchange team.

Just replace the text in bold red and run it in an Exchange Command Shell:

Set-MailboxAutoReplyConfiguration jsmith@contoso.com –AutoReplyState Scheduled –StartTime “11/2/2011” –EndTime “11/9/2011” –ExternalMessage “External OOF message” –InternalMessage “Internal OOF message

Sunday, October 30, 2011

AD Recycle Bin Tool

Last year Windows IT Pro magazine highlighted ADRecycleBin from Overall Solutions. It's an excellent free utility to bring back deleted items (or reanimate for earlier Active Directory installations than 2008 R2).

It's a very nice alternative to the built-in feature in Windows Server 2008 R2 and is a drastic improvement over item recovery in earlier versions of Active Directory with a great GUI interface.

They have a couple of other interesting products in Maven, ResetPass and Action Engine, not everything is free, but it's close.

Update: Unfortunately the original site and tools are gone, but the author was kind enough to share it with me. Here's the app, at least until I'm told not to share it online.

Thursday, October 27, 2011

Sysinternals

If you're in IT working with Windows and haven't heard of Sysinternals, you may want to check to see if you've been living under a rock.

Sysinternals started as the community or free arm of Winternals, the money making portion of the company. Microsoft purchased Winternals back in 2006 for its IP and brain-trust. Mark Russinovich has been the most active of the original staff, appearing at numerous conferences, blogging and evangelising the Microsoft operating systems.

The Sysinternals site has numerous, extremely useful troubleshooting and informational utilities; so much so I could devote this blog to their tools for the next year or three. Since access to the site is free, as are the downloads, help files and instructions, I'll just highlight a few things here...

Utilities:
Autoruns - Displays list of applications, drivers loaded and much more, that start at boot time. Includes locations of registry and file locations. Great for hunting malware.
Process Explorer - Displays all running processes and subprocesses, plus open handles, threads, paths, a veritable cornucopia of information. Task manager wishes it was this great.
Process Monitor - Allows you to monitor file system, registry, process, thread and DLL activity in real-time.
TCPView - Get detailed listings of all TCP and UDP endpoints on your system, including source and destination.

The Learning Resources are also impressive, with great videos and articles .

And as I mentioned, this is all free.

Wednesday, September 21, 2011

WMIC to the Rescue

A recent project had me trying to script the retrieval of the Dell Service Tag. Luckily there's WMI Command-line to the rescue.

From a command line or in a script wmic bios get serialnumber will display or grab the Dell Service Tag.

Furthermore, you can use the WMI Command-line to retrieve all kinds of system data and even make configuration changes. Rob van der Woude's great site on scripting has a great primer and examples on using WMIC. TechNet Magazine also has a very useful article on gathering system data using WMIC in your environment.

Finally, checkout the WMI Admin Tools pack. It contains more than I want to type about here, but it gives you the ability to browse the various objects, classes and properties, plus a custom event viewer and much more. Check it out and make your (administrative) life better.

Wednesday, September 14, 2011

List of Exchange Scripts

I started following Pat Richard's blog a few months ago and have since found his scripts to be quite useful. Even if I'm not using them directly, they've been useful as a reference when writing my own.

He recently created a list of scripts available on his site; stop by and take a look.

Wednesday, March 23, 2011

Exchange Keyword Search

So you want to look for a specific word in all the mailboxes on your server without buying a 3rd party application? Try the Exchange Management Shell.

You need three things on your client system before running the command (this is not recommended to be run on the Exchange server itself)

  1. Outlook 2003+

  2. Exchange Management Tools 2007 or 2010

  3. A configured Outlook profile with a folder for the export


get-mailbox –Database "Mailbox name" | Export-Mailbox –SubjectKeywords "Keyword" –TargetMailbox "Your mailbox" –TargetFolder 'Pick one'

The fields that need changing are in red. If you have multiple databases, the command will need to be run multiple times, and of course, the larger the databases, the longer it will take to run.

Good hunting.

Ps. Thanks to SL @ TM for this tip.

Monday, January 31, 2011

Say Ninite

(Re)building systems can be quite a drag, especially once you get to the part when it's time for downloading all the 3rd party software. This would include: Flash, Java, Firefox, Skype, etc., etc.

Enter Ninite, an amazing, time saving, utility website. It works as advertised, allowing you to choose your choice of applications, whereupon it generates a custom installer that with one-click, installs everything you wanted, without toolbars and crapware that would normally be installed by default.

There's also a corporate option for using with scripts or automated deployments. This is definitely a time saver and worth a look. Did I mention it's free :)

Sunday, June 13, 2010

Script Samples

There are times when I spent an inordinate amount of time looking for just the right syntax for a command or even the correct command to get the job done. Here are four I put to use in the last few months...

Change Printer Spooler Service Recovery options to Restart
sc failure spooler reset= 60 actions= restart/600/restart/600/restart/600

Backing up an MSDE Database
osql -E -Q "BACKUP DATABASE mdss TO DISK= 'C:\BB_DB_Backup\mdss.bak'"

Copy Database and then Appending with Date
copy t:\plandata.mdb C:\PlanDataBackup /Y

For /F "Tokens=1-8 Delims=.:/ " %%a In ('Echo %Date%') Do (Set All=%%d-%%b-%%c)
@For %%a in ("plandata.mdb") do rename %%a "%%~na-%All%.mdb"

Deleting Old OWA Logs
forfiles -p "C:\inetpub\logs\LogFiles\W3SVC1" -c "cmd /c echo del \"@FILE\" & del \"@FILE\"" -d -21

Friday, April 16, 2010

How Big are those Mailboxes

One thing I truly miss about Exchange 2003 is the list of mailbox sizes that were easily accessible in the GUI. But things must move on and the display in the Exchange Management Console for both 2007 and 2010 lack the ability to populate and view this information.

Exchange Management Shell to the rescue! If you enter just the basic Get-MailboxStatistics command it will be sorely lacking (and the sizes will be in KB). The command below will get Exchange to cough up a full list and friendlier MB display suitable for analyzing in Excel.

Open Exchange Management Shell and run the following:
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label=”TotalItemSize(MB)”;expression={$_.TotalItemSize.Value.ToMB()}},ItemCount

Tuesday, March 2, 2010

Free PowerShell Editor

Yesterday I began to really dive into a new user script (which uses Exchange Management Shell) to bring it up to date and include more fields and features. As the script complexity grew, Notepad was no longer cutting the mustard.

I thought I'd be using Notepad++ or TextPad, both fine in their own right, but instead found PowerGUI. This PowerShell editor which finds syntax errors, includes definitions and much more; all for the low, low price of free. This seems to be a community supported by Quest Software who has a bunch of fine (not so free) tools for SysAdmins.

I'm now able to work on, and run, the script off network (read: at home). It's a helluva deal for the price, try PowerGUI for your next PowerShell outing.

Monday, October 12, 2009

Command Switches for MSI Packages

Microsoft has been using the Windows Installer Tool for quite some time now to make installing, patching and repairing programs a snap (installers using this will typically have an MSI extension).

One of the many benefits of this tool is the ability to script a program or patch installation using the available command-line switches, e.g.: adobe_reader.msi /qn which will install the application quietly without a UI. This can be key when making a batch file to install numerous applications and patches on a new system.

For the many available switches to use check out the full list from Microsoft.