Purpose:
Simple script to copy files from one computer or server to another in the same domain. Example can
also email a simple report of files copied. Created to move some files hourly and only email when
something was moved.

Notes:
Will not work across different domains. Account used to run task from task manager must be a domain
user with enough rights on both systems to read and write.

#=====================================================================================================#
# Copyright 2014 Robert Stacks
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
#=====================================================================================================#
# Original Author: Robert Stacks
# Original Script URL: https://randomtechminutia.wordpress.com/2014/02/03/copy-files-from-one-server-to-another-in-the-same-domain/
# Date: 2/3/2014
# Updated:
# Version: 1.0
#
# Purpose:
# Simple script to copy files from one computer or server to another in the same domain. Example can
# also email a simple report of files copied. Created to move some files hourly and only email when
# something was moved.
#
# Many of the user variables are set with $TRUE or $FALSE for on or off.
#
# Will not work across different domains. Account used to run task from task manager must be a domain
# user with enough rights on both systems to read and write.
#
# Update Notes:
#
#=====================================================================================================#
# Email Settings
$fromAddr = "From@domain.com" # Enter the FROM address for the e-mail alert
$toAddr = "To@domain.com" # Enter the TO address for the e-mail alert
$smtpsrv = "mail.domain.com" # Enter the FQDN or IP of a SMTP relay
# Files to Copy and where they are going
# Local Files should be in the formate of C:\Folder\* for Files only or C:\Folder to copy the folder as well
$Localfiles = "C:\Folder\*"
# Remote Path should be UNC path with admin share example \\hostname\c$\pathtocopyto
$Remotefiles = "\\hostname\c$\pathtocopyto"
#Enable or Disable Script functions
$EmailAlerts = $TRUE # Turn e-mail alerts on or off. $FALSE or 0 = off
$TestfromPrompt = $FALSE # Turn on output from command line. $FALSE or 0 = no output
$RemoveFilesafterCopy = $TRUE # Remove files after files have been copied over?
#===========================#
#Main Script #
#===========================#
#Get the names of the files we want to transfer
$files = Get-childitem "$Localfiles" |foreach { $_.Name}
if ($files -ne $null)
{
#Generates output to command line if Value = True
if ($TestfromPrompt -eq $TRUE)
{
Write-Host "These are the files being copied"
$files
}
#Copy files to remote computer
copy-item -path "$Localfiles" -Destination "$Remotefiles" -Recurse
#Remove Files if Value = True
if ($RemoveFilesafterCopy -eq $TRUE)
{
#Remove Files after they have been moved
Remove-Item "$Localfiles"
}
#Send Email Alert if Value = True
if ($EmailAlerts -eq $TRUE)
{
$date = Get-Date -Format g
Send-MailMessage -To $toAddr -From $fromAddr -Subject "$date Files Copied" -Body "The Following Files were moved: " + $files -SmtpServer $smtpsrv
}
}

Simple Script that will create a text file that another scheduled script can then use to as the password for some account. Example, you want a script to auto run and remote into some domain, machine, etc but you want to secure the password used by the script. So it will not be stored in plain text on a server in a script file. This will get that done.

You call this script from commandline once and then put the text file “securestring.txt” in a call in the automated script.

1. Create a file called encryptpassword.ps1 and put the following in it.

Notes:
I haven’t formated this script in the typical fashion I normally do.

Must be run on a DC with Domain Rights.

# Get today's date
$date = get-date
# Set variable LLTSlimit to today's date minus 90 days
$LLTSlimit = (Get-Date).AddDays(-90).ToFileTimeUTC().ToString()
# Set variable LDAPfilter as a LDAP filter to only find ACTIVE user accounts (useraccountcontrol piece) that have a lastlogontimestamp of older than 90 days
$LDAPFilter = "(&(objectCategory=Computer)(objectClass=User)(lastlogontimestamp<=$LLTSlimit)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"
#output LDAPfilter to txt file for loop
dsquery * domainroot -filter $LDAPFilter -limit 0 > D:\scripts\test.txt
#Loop through the computers that need to be disabled one at a time
FOREACH ($f in get-content D:\scripts\test.txt)
{
#disable computer and append to the old description the note about disabling account
dsmod computer $f -disabled yes -desc "$processolddesc - Disabled due to inactivity on $date"
}
exit

Purpose:
This script was used to generate a DFS Health Report and email it to the admin team on a daily basis.

Comments:
I attempted to push the report into the body of the email but Outlook did not like the formatting so instead it was added as an attachment.
This is on a Windows 2008 R2 Server using the old commandline version of DFS and its reporting. The Report does not work in some of the newer version of IE.
To view the report you have to hit F12 and then change the Document Mode: IE quirks to IE5 Quirks

#=====================================================================================================#
# Copyright 2011 Robert Stacks
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#=====================================================================================================#
# Author: Robert Stacks
# URL: RandomTechMinutia.wordpress.com
# Date: 11/30/2012
# Updated: 11/30/2012
# Version: 0.1
#
# Purpose:
# Generate a DFS Admin Report and Email it to the admin team it must be viewed with IE due to HTML/Java formatting
#=====================================================================================================#
#Get todays Date
$date = Get-Date
#===========================#
#User Adjustable Variables #
#===========================#
#Mail Server Variables
$SMTPserver = "mail.domain.com"
$from = "DFSReplicationReport@domain.com"
$to = "Youremail@domain.com"
$subject = "DFS Replication Health Report " + $date
$emailbody = "Attached is the Report"
#DFS Info
#Note: $ReplicationGroup=`"Corp Office to Phoenix`", if your group name has no spaces you can remove the `"
#the dfsadmin command can be a little unforgiving about quotes you may have to adjust your values accordingly.
$ReplicationGroup=`"Your Replication Group`"
$MemeberServer="ServerName"
$SaveReportLocation="C:\DFSReports"
#===========================#
#Main Script #
#===========================#
#Generate DFS Report
dfsradmin health new /RgName:$ReplicationGroup /RefMemName:$MemeberServer /repname:$SaveReportLocation
# Send email
Send-MailMessage -From $from -To $to -SmtpServer $SMTPserver -Subject $subject -Body "Attached is the DFS Health Report. It must be viewed in IE" -Attachments ("C:\DFSReports\Health-Corp Office to Phoenix.html")

One of those basic things that Microsoft changed for us, when logged into a Windows 7 or Server 2008 R2 server and you ping itself you get a IP6 address. Few shops have converted to IP6 yet so this is how you change that address back to IP4. I do this in my Windows Templates in VMware.

Open RegEdit, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tcpip6\Parameters

This is something I worked up to scan a list of servers, determine their drive space usage, and then calculate a cost to charge a customer. The script obviously was written with a client-customer, hosted solution in mind. All that said I scrubbed the code of anything that was actually used by the client/customer but the script has some pretty interesting features that took me a while to put together using hints from others on the web.

The most interesting aspect of this script is the ability to remote into a remote domain and then function as if you were a member of that domain.

This script has a specific purpose where I used it but it could be modified to do something else, so I’m posing it here if nothing else as a reference/example. Also keep in mind this script was chopped up a good bit to publish to the web so it might be a little buggy now.

Purpose:Report on remote server hard drive usage when said server is in another domain and alert when usage hits a ceiling in GB.

Requirements:Quest.ActiveRoles.ADManagement on the system running the script
Domain admin or at least rights to log onto the servers to be scanned
The PC or Server running the script must be able to resolve the foreign domains DNS and Servers FQDN

Other:
The script can also be used with some minor modifications to generate a cost based on Storage usage, this is how I used it.
Line 183 “Some Cost” is the line I used to input a bit of math to determine a cost. That line along with 133 could be removed if so desired.
The script is designed to log into a remote domain or work group, if this wasn’t the case it could be converted into a much simpler/smaller script.

Here is a report I put together to quickly view all VMs their VMDKs and the Datastores those VMDKs are sitting on. This is not meant to be a report to view total storage or free space on either the VMs or their Datastores, nor are we looking for orphaned vmdk files. Although I may add those features to this report later on.

Update 3/13/2014: Script now reports on Size and how the data is presented has been improved.

Issue: Review VMDK files for any that don’t have the same name as the VM names in VCenter.

Purpose: Scan and report on VMware VM’s VMDKs and what Datastores they are tied to.

Side Notes:

You must have Powercli installed on the machine this report runs off of.

The admin account used must have enough permissions to run the given commands.

It is possible to have two VMs in vCenter with the same name. So in the report you may see a single server when in fact it is two separate servers.

If that happens you’ll see a single instance of that VM’s name with more than the expected number of disk.

A while back we setup and installed QRadar as syslog server for our IT Infrastructure. The system works pretty well, Linux and Unix hosts send syslogs to it. Routers and Switches and other such devices are checked via snmp. The real challenge was to get Microsoft 2008 R2 servers working with it.

The way it works with Microsoft, is that QRadar logs into a server with Admin rights, and creates a DCOM object that then fetches logs via WMI and sends them back to the QRadar Server. This requires a very specific set of rights including the taking ownership of two registry keys that by default have the TrustedInstaller account as the owner. Seeing as I need to do this as I setup new servers, as part of a auto install process I wanted to script the whole thing.

The big challenge was scripting a ownership change of the registry. I ended up having to revert to some VB to make it happen. However it all runs as a powershell script. So here are the highlights and that part of the script.

Problem

Need to grant special permissions on a Registry Key via Script

Need to take ownership of a Registry Key via Script

Key Points

You must run this script as the user that is taking ownership

You can’t give ownership it must be taken thus the 1st bullet

Make sure to take a backup of your registry before you change it or permissions

Special thank you to Tome Tanasovski on the technet forms who wrote this originally, I just added comments and figured out how to make it work with a hive key I was interested in that had a special character in it.