Thursday, April 2, 2015

Find the Service Tags of all Computers in your environment using Powershell and bat



Log into the domain controller or a workstation which has Active Directory Powershell module

Run the following command to create a list of computers in your environment

Get-ADComputer -Filter * |ft Name |Out-File computers.txt

Open notepad and create a bat file with the wmic call parsing the newly created computer text file.

wmic /NODE:@"c:\scripts\computers.txt"

bios get serialnumber > serialnumbers.txt

Execute the bat

Decrypt all files on a file Server effected by Cryptolocker with Powershell


Go to the fireye website to see if your version of Cryptolockers key has been found https://www.decryptcryptolocker.com/

Upload an unlockable file and wait for the email with the encryption key to be sent. Paste the encryption key into the key parameter for the script.

Save the script and the decryptolocker.exe command in the same folder path.
Change the parameter for the fileserver to match the effected directory

This script will traverse directories and parse through all items which match the encryption key, create a backup and then restore the file. Make sure you have adequate room on your fileserver to hold twice the amount of data.

If all the files are not successfully decrypted it is likely your site was hit by multiple instances of Cryptolocker and a separate key will be needed for the additional files.

After the files are verified as successfully decrypted go ahead and delete the backup copies.

$key = "-----BEGIN RSA PRIVATE KEY----- Key from email Pasted here -----END RSA PRIVATE KEY----- "

$list = (get-childitem  "\\fileserver\user shares" | where {$_.PSIsContainer} | select-object FullName)


foreach ($_ in $list) { echo "Yes" | .\Decryptolocker.exe --key "$key" -r $_.FullName }

Create a Report from SQL and email it in Powershell

Create a Report from SQL and email it in Powershell





 #Connection Strings
    $Database = "MSSQL"
$Server = "SQL-SERVER"
    #SMTP Relay Server
    $SMTPServer = "relay.mailserver.org"
    #Export File
    $AttachmentPath = "C:\Scripts\report.csv"
    # Connect to SQL and query data, extract data. The SQL Query Commandlet will take any Query in sqlcmd
    $SqlQuery = "SELECT Item1, Item2, Item3, Item4    FROM sometable where TimeStamp >= GETDATE() - 1 "
    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $SqlConnection.ConnectionString = "Data Source=$Server;Initial Catalog=$Database;Integrated Security = True"
    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
    $SqlCmd.CommandText = $SqlQuery
    $SqlCmd.Connection = $SqlConnection
    $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
    $SqlAdapter.SelectCommand = $SqlCmd
    $DataSet = New-Object System.Data.DataSet
    $nRecs = $SqlAdapter.Fill($DataSet)
    $nRecs | Out-Null
    #Populate Temporary Table
    $objTable = $DataSet.Tables[0]
    #Export Data to CSV File
    $objTable | Export-CSV $AttachmentPath
    #Send SMTP Message
    $Mailer = new-object Net.Mail.SMTPclient($SMTPServer)
    $From = "reports@yourdomain.com"
    $To = "managers@yourdomain.com"
    $Subject = "Daily Report"
    $Body = "Attached is the Daily Report"
    $Msg = new-object Net.Mail.MailMessage($From,$To,$Subject,$Body)
    $Msg.IsBodyHTML = $False
    $Attachment = new-object Net.Mail.Attachment($AttachmentPath)
    $Msg.attachments.add($Attachment)

    $Mailer.send($Msg)
XML Parsing in Powershell

Get the schema in xml
[xml]$xml = Get-Content .\acesdata.xml

Open up the file in excel as an XML Source Task Pane to find which node you are going to start parsing












In this example the Node will be Header and the fields I want to parse are Company, TransferDate, and EffectiveDate

























Run the following command to parse the data
$xml.SelectNodes('//Header') | Select Company,TransferDate,EffectiveDate |Export-csv aces.csv


Wednesday, May 14, 2014

Firewall Configuration Palo Alto Exchange 2010 / 2013

Firewall Configuration Palo Alto Exchange 2010 / 2013

1. Create an external DNS entry for Outlook Web Access in with your ISP

2. Create a NAT rule for the external IP to the internal IP of the Hub /Cas server

3. Configure the allow traffic rules as follows





4. Verify OWA is accessible externally

Extend Active Directory Schema using a custom Ldf file

Extend Active Directory Schema using a custom Ldf file
 

1. Copy the ldf file and paste it into notepad
 

2. Find and replace dc=x with dc=domain, dc=com

3.  Log into a domain controller and run ldifde –I –f ldiffilename.ldf –v –j C:\Temp\




 4. Verify the Schema extension using ADSIedit.msc










Demote a 2003 Domain Controller in a 2012 DC Environment



Demote a 2003 Domain Controller in a 2012 DC Environment
Log into the 2012 Domain controller and
Navigate from Dashboard  to Tools in Active Directory sites and Services right click on the 2012 Domain controller and click properties. Verify the Domain Controller is a Global Catalog Server



Open up Powershell and run the following cmds
Import-Module ActiveDirectory
Move-ADDirectoryServerOperationMasterRole -Identity "Target-DC" -OperationMasterRole 0,1,2,3,4
This moves the FSMO roles to the 2012 DC


Netdom query FSMO



This verifies the roles have been successfully transferred 



Verify the 2012 Domain controller no longer has the DNS network settings of the 2003 DC


Log into the 2003 Domain Controller

Stop the services DNS server  and netlogon on the 2003 Domain Controller



Run dcpromo from the 2003 DC


Click next

Click Next


Click next

Enter a new password for the local administrator and Click Next twice






Click Finish

Restart the 2003 Server