Richard's Minick's Tech Blog
This blog contains various Powershell scripts, Microsoft Windows Server Tips and more... Some created by myself or snippets from other sites.
Wednesday, March 6, 2013
Monday, March 4, 2013
Friday, February 22, 2013
Wednesday, May 30, 2012
Microsoft ADRAP
Spending the week with a Microsoft AD Engineer fixes many issues from our ADRAP (Active Directory Risk Assessment). Sure leaning a lot more about AD that I never knew since we are having to dive into adsiedit, vbscript to fix a FSMO role issue, etc.
Monday, May 7, 2012
Sunday, May 6, 2012
Printing results from an Active Directory Administrative Center query
Recently a question was asked on the blog regarding printing queries from Active Directory Administrative Center (ADAC). There is no native functionality for printing queries performed in ADAC, but there is a workaround.
1. Open ADAC and create a query:
2. Convert the query to LDAP:
3. Open the Active Directory module for Windows PowerShell and copy the filter into the Windows PowerShell command window:
You can now print the corresponding text file that contains the results of your query.
Complements of Microsoft.
Program to check for corrupted MP3 files
If you have a 20,000+ MP3 file library like I do, you will end up with a few corrupt MP3 files over time. I had a few that kept crashing iTunes during the iTunes Match process. I found the application to help me find the offending files.
The freeware program can be found here!
The freeware program can be found here!
Thursday, May 3, 2012
PKI/CA Script Needed
Does anyone have any Powershell scripts to query the Certificate Authorities in a domain to pull a list of expiring certificates?
I found this link for the Microsoft Certutil.exe which will be helpful. I'd still prefer a PS way of getting the data.
I found this link for the Microsoft Certutil.exe which will be helpful. I'd still prefer a PS way of getting the data.
Wednesday, May 2, 2012
IIS Log Files - Compress and Remove
Original Posting
Given one or more directories, use PowerShell and 7-Zip to parse through the contents for the previous month's IIS log files. Zip them up, verify the .zip and delete the original log files. The resulting compressed archive will be about 4.5% of the size of the original log files.
Given one or more directories, use PowerShell and 7-Zip to parse through the contents for the previous month's IIS log files. Zip them up, verify the .zip and delete the original log files. The resulting compressed archive will be about 4.5% of the size of the original log files.
Description
Given one or more website directories, parse through the directory contents to find the previous month's IIS log files. Zip them up, verify the .zip, and delete the original log files. The resulting compressed archive will be about 4.5% of the size of the original log files.
This script is best utilized by setting a scheduled task to run it during off-peak times because the compression process will max out all available cores unless you tell 7-Zip not to do so (in its own settings, not from this script.)
7-Zip is required for this to work. By default this script looks for the 7-Zip executable, 7za.exe, in C:\7-Zip\
Coming Soon!
The next major version of this script will provide the option of using the Web Administration (IIS) provider to automatically enumerate and backup log files for all IIS sites.
Update History
Updated 20120309 - Fixed bug in handling no files found to backup. Thanks to HellfishMike!
Updated 20120222 - Checks for 7-Zip and alerts if not present, creates temp folder if not present, correctly handles no files being found to backup.
Updated 20120105 - Slightly better error notification and a new temp file location.
Script
PowerShell
#Windows PowerShell Code################################################### # # NAME: compress-remove-logs.ps1 # VERSION: 1.4.2 # DATE: 20120309 # # AUTHOR: Bernie Salvaggio # EMAIL: BernieSalvaggio(at)gmail(dot)com # TWITTER: @BernieSalvaggio # WEBSITE: http://www.BernieSalvaggio.com/ # # COMMENT: Given one or more website directories, parse through the # directory contents to find the previous month's IIS log # files. Zip them up, verify the .zip, and delete the original # log files. The resulting compressed archive will be about # 4.5% of the size of the original log files. # # This script is best utilized by setting a scheduled task # to run it during off-peak times because the compression # process will max out all available cores unless you tell # 7-Zip not to do so (in its own settings, not from this script) # # REQUIRED: 7-Zip is required for this to work. By default this script # looks for the 7-Zip executable, 7za.exe, in C:\7-Zip\ # # You have a royalty-free right to use, modify, reproduce, and # distribute this script file in any way you find useful, provided that # you agree that the creator, owner above has no warranty, obligations, # or liability for such use. # ########################################################################### # Build all the pieces for emailing results $ServerName = gc env:computername $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage # Mail server settings for you to change according to your environment $SmtpClient.Host = "192.168.1.10" $MailMessage.from = ($ServerName + "@yourDomain.com") $MailMessage.To.add("serverteam@yourDomain.com") $MailMessage.Subject = $ServerName + " IIS Log File Archive Results" # The folder(s) you want to back up # IMPORTANT: For each target path you specify here, there MUST be a matching BackupsPath and TargetPathName defined as well. $TargetPaths = @("C:\WebFiles\yourWebsite.com\logs\W3SVC1") # Where you want the backups saved # There's a 1 to 1 relationship between the $BackupsPath and $TargetPaths # For each $TargetPaths you add, you need another $BackupsPath to go along with it $BackupsPath = @("C:\WebFiles\yourWebsite.com\logs\W3SVC1\") # Short name to append to the filename of the .zip backup file (in case the backup path is the same for multiple target paths) # Each entry here should match the corresponding one in the $TargetPaths array $TargetPathName = @("iis-logs") # Temp file that stores the list of files for 7-Zip to archive $TempFolder = "C:\temp" if (!(Test-Path $TempFolder)) { New-Item $TempFolder -type directory } $ArchiveList = "$TempFolder\listfile.txt" # Temp file used to write the 7-Zip verify results to, then read into the email message body $ArchiveResults = "$TempFolder\archive-results.txt" $ArchiveExtension = ".zip" # Just some things to get started... $TargetPathNameCounter = 0 $BackupPathCounter = 0 $CurrentDate = Get-Date $ArchiveDate = $CurrentDate.AddMonths(-1).ToString("MMMyyyy") $FilesFound = $false # Path to the 7-Zip executable $7z = "C:\7-Zip\7za.exe" if (!(Test-Path $7z)) { $MailMessage.Body = "Error: 7-Zip not found at $7z" $SmtpClient.Send($MailMessage) Exit } foreach ($TargetPath in $TargetPaths) { $FilesFound = $false # Directory list, minus the folders, where the last write time = the archive date, group the files by month/year dir $TargetPath | where {!$_.PSIsContainer} | where {$_.extension -eq ".log"} | where {"{0:MMM}{0:yyyy}" -f $_.LastWriteTime -eq $ArchiveDate} | group {"{0:MMM}{0:yyyy}" -f $_.LastWriteTime} | foreach { # Used for tracking in case no files meeting the backup criteria are found $FilesFound = $true # Generate list of files to compress. For list files, 7-Zip uses UTF-8 encoding by default $_.group | foreach {$_.fullname} | out-file $ArchiveList -encoding utf8 # Declare/Clear the email message body $MailMessage.Body = "" # Create the full name of the zip file we'll create $ZipFileName = $BackupsPath[$BackupPathCounter]+$TargetPathName[$TargetPathNameCounter]+$_.name+$ArchiveExtension # Archive the list of files $null = & $7z a -tzip -mx8 -y $ZipFileName `@$ArchiveList # Check if the operation succeeded if($LASTEXITCODE -eq 0){ # If it succeeded, double check with 7-Zip's Test feature $null = & $7z t $ZipFileName | out-file $ArchiveResults if($LASTEXITCODE -eq 0){ # Verify success, write out the contents of the verify command to the email message body foreach ($txtLine in Get-Content $ArchiveResults) {$MailMessage.Body += $txtLine + "`n"} # Delete the original files $_.group | Remove-Item } else { $MailMessage.Body = "There was an error verifying the 7-Zip archive $ZipFileName" } } else { $MailMessage.Body = "There was an error creating the 7-Zip archive $ZipFileName" } $SmtpClient.Send($MailMessage) } if (!$FilesFound) { # No files found to parse $MailMessage.Body = "Error: No files found to archive in $TargetPath" $SmtpClient.Send($MailMessage) } # Test to make sure the files exist before removing. If there aren't any files to archive, these two files won't exist. if (Test-Path $ArchiveList) { Remove-Item $ArchiveList } if (Test-Path $ArchiveResults) { Remove-Item $ArchiveResults } $BackupPathCounter++ $TargetPathNameCounter++ }
Client System Administration tool 1.0.2
Client System Administration tool 1.0.2
Code can be downloaded from the original technet post here.
ACSA was built with the Helpdesk administrator in mind. Troubleshooting desktop issues requires a vast array of tools and knowledge. ACSA brings those tools together in one central location and adds additional functionality.
This script is tested on these platforms by the author. It is likely to work on other platforms as well. If you try it and find that it works on another platform, please add a note to the script discussion to let others know.
Online Peer SupportFor online peer support, join The Official Scripting Guys Forum! To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
This script is tested on these platforms by the author. It is likely to work on other platforms as well. If you try it and find that it works on another platform, please add a note to the script discussion to let others know.
Online Peer SupportFor online peer support, join The Official Scripting Guys Forum! To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
DisclaimerThe sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
ACSA Requirements:
- Powershell v2
- Quest ActiveDirectory Tools for Powershell (http://www.quest.com/powershell)
- PSExec.exe (http://technet.microsoft.com/en-us/sysinternals/bb897553)
Optional: Trace32.exe (For tailing log files)
Usage: Run the ACSA.ps1 script and type in a partial computer name to search for it in Active Directory. This brings up a second form with a list of computers that match the search criteria and the users that are logged into them. If you already know the name of the computer you would like to manage remotely, you can type that directly into the text box on the main form.
Features:
- Powershell v2
- Quest ActiveDirectory Tools for Powershell (http://www.quest.com/powershell)
- PSExec.exe (http://technet.microsoft.com/en-us/sysinternals/bb897553)
Optional: Trace32.exe (For tailing log files)
Usage: Run the ACSA.ps1 script and type in a partial computer name to search for it in Active Directory. This brings up a second form with a list of computers that match the search criteria and the users that are logged into them. If you already know the name of the computer you would like to manage remotely, you can type that directly into the text box on the main form.
Features:
- Connects to currently logged-in domain on startup
- Search for PC - Search Active Directory for computers matching the string in the textbox
- System Info - Gathers info about PC, user session, make/model, hardware, OS, networking and McAfee
- Local Admins - Enumerates local administrators and allows you to remove them
- Applications - Enumerates installed software and allows you to uninstall
- Startup Items - Enumerates startup items and allows you to remove them
- Processes - Enumerates running processes and allows you to kill them
- Remote Desktop - Remote desktop into computer
- Remote Assistance - Initiate remote assistance session with remote computer
- View C Drive - Opens explorer to the C drive of remote computer
- Restart Computer - Restarts remote computer (Includes confirmation)
- File Menu
- Connect to domain... - Connect to a different domain
- Find User in AD - Enter user's name, search for it in AD and output to Grid View
- Find User on PC - Enter computer name, see who is logged into it and then search for that user in AD
- View Menu
- View McAfee AntiVirus logs
- View WSUS logs
- View Event Viewer
- View Services
- View Local Users/Groups
- Quick Fix
- Group Policy Update - Run 'gpupdate /force'
- Lock Computer - Lock the remote computer
- McAfee DAT Update - Updates DATS
- Reader Fix IE Plugin - Update Reader's exe path in registry to fix IE plugin
- Rename Computer - Renames remote computer and reboots it
- WSUS - Detect - Run 'wuauclt /detectnow'
- WSUS - Report - Run 'wuauclt /reportnow'
- WSUS - Reset Client ID - Fixes an issue where computers do not show up in WSUS
Blog Posting: Arposh Client System Administration
Subscribe to:
Posts (Atom)