Because so many of the functions were not only identically named, but also similarly constructed, I decided to add commented identifiers to the beginning and ending of each JS file.
This could be done in a number of ways, but given my recent forays into using PowerShell scripts, I chose that route again.
The text of the script is below. What this script does is recursively search through the file path in line 1, choosing only files that have the extension after the filter switch (.js in this case). Looping through these file names, each file is read into memory (using Get-Content). The root of the file is then removed with the first replace command, and for aesthetics, I chose to change backslashes into forward slashes with the second one (lines 4 and 5). Notice that backslashes must be escaped by using an extra backslash, whereas forward slashes are not escaped. Also, in case you’re wondering, the backtick-n (`n) is the newline character in PowerShell. The Set-Content cmdlet is used to add the “$newline” string and then the original file content. The Add-Content cmdlet is then used to add the line marking the end of the file.
Adding a user to multiple distribution lists via Outlook can be a tedious process if many lists are involved. For today’s problem, I had to add a user to many lists that have a similar prefix. Instead of spending a an hour or more of adding the user to the DLs through the Global Address Book, I decided to use PowerShell.
This script, which I call “addtodl.ps1”, receives three parameters: the user’s email address, the name of the distribution list – which can include a wildcard character (*) to get multiple names, and the Exchange Server FQDN.
By running this at the PowerShell command line with the parameters, you will be able to add the user to all distribution lists in the query that you manage. Those that you do not have access to will cause an error that will not halt the script. A dialog box asking for your username and password will appear first.
When I have time, I intend to revisit this issue to get more useful information such as owner email addresses. Currently, if you uncomment the lines inside the foreach statement, the owners of each DL will be printed on the screen as well. It’s not too useful yet – which is why I still have it commented here.
I had mistakenly allowed a string to be appended multiple times on the names of files in a folder on my Windows server by a Python script on which I was working. It was a date string that was applied several times: “_2015-11-04_2015-11-04_2015-11-04_2015-11-04_2015-11-04”
I wanted to remove this string from multiple files that were named MailXXXXXXXXX_2015-11-04_2015-11-04_2015-11-04_2015-11-04_2015-11-04.cfmail (the Xs represent numbers).
I tried using the old RENAME command like this: rename “_2015-11-04_2015-11-04_2015-11-04_2015-11-04_2015-11-04.cfmail” “/…(53 slashes here)…/.cfmail”, but I kept getting errors saying the file was in use.
After making the necessary changes, I logged onto the server, opened a Command Prompt with admin privileges, and started PS. I navigated to the folder that contained the files to be renamed and created a script I called rename.ps1 here.
PowerShell is a very powerful tool for Windows administrators and developers alike.
I wanted to find out if a particular user ID was in the local admin group on all servers in my domain. Fortunately, someone had written a script (source link no longer exists) to check that very thing on the server you’re logged onto.
However, I wanted to check not just the server I’m on, but on all servers in the domain.
The script below, called findadmins.ps1, should do just that: