2011/04/26
What Anti-Virus scanning exclusions should be considered for system and servers ?
Consider the following file scanning exceptions for your Anti-Virus software where applicable:
NOTE: The %systemroot% is normally the C:\WINDOWS or C:\WINNT directory depending on your OS.
NOTE: the %systemroot% variable will not work as an exclusion for some OSs. So make sure to spell out full path in your exclusion files (GPO or via AntiVirus Server)
1.) %systemroot%\System32\Spool (and all the sub-folders and files)
2.) %systemroot%\SoftwareDistribution\Datastore
Refer to the following article for information:
KB822158 - Virus scanning recommendations for computers that are running Windows Server 2003, Windows 2000, or Windows XP http://support.microsoft.com/kb/822158
3.) Any Network Drives that are mapped.
2011/04/25
Use PowerShell to Identify Non-Standard Windows Service Accounts
<#
.SYNOPSIS
Identifies services with nonstandard accounts
.DESCRIPTION
Retrieves services that use accounts other than LocalSystem, LocalService or NetworkService
.PARAMETER computername
one or more computernames or IP addresses
you will need local administrator privileges, and the firewall needs to allow access
to enable firewall access, run this command on target machines:
netsh firewall set service type = remoteadmin mode = enable
.EXAMPLE
Get-NonstandardService
lists services with nonstandard accounts on local machine
.EXAMPLE
Get-NonstandardService -computername 10.10.10.33
lists services with nonstandard accounts on remote machine with IP 10.10.10.33
.EXAMPLE
Get-NonstandardService -computername 10.10.10.33, 127.0.0.1, serv12-1, client3
lists services with nonstandard accounts on four machines (including local system)
.LINK
http://www.powershell.com
#>
function Get-NonstandardService {
param(
[String[]]
$computername = '127.0.0.1'
)
# server-side WMI query to minimize network traffic and maximize performance
$wql = 'Select Name, DisplayName, StartName, __Server From Win32_Service WHERE ((StartName != "LocalSystem") and (StartName != "NT Authority\\LocalService") and (StartName != "NT Authority\\NetworkService"))'
# examine all computers submitted:
$computername |
ForEach-Object {
Write-Progress 'examining computer:' $_
# create new object to return information
$rv = New-Object PSObject | Select-Object Computer, Result, Name, DisplayName
$rv.computer = $_
# search for nonstandard services
try {
# always return result as array
$result = @(Get-WmiObject -Query $wql -ComputerName $rv.computer -ErrorAction Stop | Sort-Object DisplayName)
# no results?
if ($result.Count -eq 0) {
# then all services use standard accounts, good:
$rv.Result = 'OK'
$rv
} else {
# return a result set for each nonstandard service
$result | ForEach-Object {
$rv.Computer = $_.__Server
$rv.Name = $_.Name
$rv.DisplayName = $_.DisplayName
$rv.Result = $_.StartName
$rv
}
}
}
catch {
# WMI was unable to retrieve the information
switch ($_) {
# sort out most common errors and return qualified information
{ $_.Exception.ErrorCode -eq 0x800706ba} { $rv.Result = 'WARN: Unavailable (offline, firewall)' }
{ $_.CategoryInfo.Reason -eq 'UnauthorizedAccessException' } { $rv.Result = 'WARN: Access denied' }
# return all other non-common errors
default { $rv.Result = 'WARN: ' + $_.Exception.Message }
}
# return error information
$rv
}
}
}
2011/02/16
Active Directory - List and Set/Fix AD users not inheriting permissions
If the Allow and Deny permission check boxes in the various parts of the access control user interface are shaded when you view the permissions of an object, the object has inherited permissions from a parent object. You can set these inherited permissions by using the Permissions tab of the Advanced Security Settings properties page.
Check Technet for more information
Here is the PowerShell way to check which users does not have Inheriting Permission and How to Enabling it for all your users. You will need to user Quest Active Directory Snapin
List Users without Inheriting Permission
# This Command will list the user not inheriting Permission
Get-QADUser -SizeLimit 0 | `
Where-Object {$_.DirectoryEntry.PSBase.ObjectSecurity.AreAccessRulesProtected}
Enabling Inheriting Permission for all Users
# This Command will enable inheriting Permission for all the accounts
Get-QADUser -SizeLimit 0 | `
Where-Object {$_.DirectoryEntry.PSBase.ObjectSecurity.AreAccessRulesProtected} | `
Set-QADObjectSecurity -UnLockInheritance
2011/02/15
How to find running processes and their port number
Source
The netstat command line utility displays protocol statistics and current TCP/IP network connections. If we want to display the associated process identifier (PID) of each process we add the -o parameter.
function Get-NetworkStatistics
{
$properties = 'Protocol','LocalAddress','LocalPort'
$properties += 'RemoteAddress','RemotePort','State','ProcessName','PID'
netstat -ano | Select-String -Pattern '\s+(TCP|UDP)' | ForEach-Object {
$item = $_.line.split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)
if($item[1] -notmatch '^\[::')
{
if (($la = $item[1] -as [ipaddress]).AddressFamily -eq 'InterNetworkV6')
{
$localAddress = $la.IPAddressToString
$localPort = $item[1].split('\]:')[-1]
}
else
{
$localAddress = $item[1].split(':')[0]
$localPort = $item[1].split(':')[-1]
}
if (($ra = $item[2] -as [ipaddress]).AddressFamily -eq 'InterNetworkV6')
{
$remoteAddress = $ra.IPAddressToString
$remotePort = $item[2].split('\]:')[-1]
}
else
{
$remoteAddress = $item[2].split(':')[0]
$remotePort = $item[2].split(':')[-1]
}
New-Object PSObject -Property @{
PID = $item[-1]
ProcessName = (Get-Process -Id $item[-1] -ErrorAction SilentlyContinue).Name
Protocol = $item[0]
LocalAddress = $localAddress
LocalPort = $localPort
RemoteAddress =$remoteAddress
RemotePort = $remotePort
State = if($item[0] -eq 'tcp') {$item[3]} else {$null}
} | Select-Object -Property $properties
}
}
}
Working with SID
Account Name to SID
#
#Get "fabrikam, kenmyer" to SID
$objUser = New-Object System.Security.Principal.NTAccount("fabrikam", "kenmyer")
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$strSID.Value
SID to Account Name
#
# translate "S-1-5-21-1454471165-1004335555-1606985555-5555" to Account Name
$objSID = New-Object System.Security.Principal.SecurityIdentifier `
("S-1-5-21-1454471165-1004335555-1606985555-5555")
$objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
$objUser.Value
2011/02/08
Microsoft Windows 7 and Windows Server 2008 R2 Online Videos
Windows 7 Feature Overview
http://go.microsoft.com/?linkid=9670048&clcid=0x409
Demo 1: Introducing DirectAccess
http://go.microsoft.com/?linkid=9670126&clcid=0x409
Demo 2: Using Search Federation
http://go.microsoft.com/?linkid=9670127&clcid=0x409
Demo 3: Using Windows PowerShell 2.0
http://go.microsoft.com/?linkid=9670128&clcid=0x409
Demo 4: Configuring AppLocker
http://go.microsoft.com/?linkid=9670129&clcid=0x409
Demo 5: Troubleshooting Windows 7
http://go.microsoft.com/?linkid=9670130&clcid=0x409
Windows 7 Deployment Enhancements
http://go.microsoft.com/?linkid=9670049&clcid=0x409
Demo 1: Modifying Windows 7 Operating Systems with DISM
http://go.microsoft.com/?linkid=9670131&clcid=0x409
Demo 2: Automating Deployment Using Windows Deployment Services
http://go.microsoft.com/?linkid=9670132&clcid=0x409
Demo 3: Provisioning Virtual Machines
http://go.microsoft.com/?linkid=9670133&clcid=0x409
Windows 7 Manageability Solutions
http://go.microsoft.com/?linkid=9670050&clcid=0x409
Demo 1: Configuring Group Policy
http://go.microsoft.com/?linkid=9670134&clcid=0x409
Demo 2: Using Windows PowerShell 2.0
http://go.microsoft.com/?linkid=9670135&clcid=0x409
Demo 3: Using Support Tools
http://go.microsoft.com/?linkid=9670136&clcid=0x409
Demo 4: Exploring System Recovery Options
http://go.microsoft.com/?linkid=9670137&clcid=0x409
Technical Overview of Windows Server 2008 R2 Part 1
http://go.microsoft.com/?linkid=9670051&clcid=0x409
Demo 1: Using Hyper-V™ Live Migration
http://go.microsoft.com/?linkid=9670138&clcid=0x409
Demo 2: Booting from Virtual Hard Disk (VHD)
http://go.microsoft.com/?linkid=9670139&clcid=0x409
Demo 3: Administering Windows PowerShell™ Remotely
http://go.microsoft.com/?linkid=9670140&clcid=0x409
Demo 4: Using Active Directory® Management Enhancements
http://go.microsoft.com/?linkid=9670141&clcid=0x409
Technical Overview of Windows Server 2008 R2 Part 2
http://go.microsoft.com/?linkid=9670052&clcid=0x409
Demo 1: Improving Availability and Scalability with Server Core
http://go.microsoft.com/?linkid=9670142&clcid=0x409
Demo 2: Managing Web Applications with the Configuration Editor
http://go.microsoft.com/?linkid=9670143&clcid=0x409
Demo 3: Installing and Using the Windows PowerShell™ Snap-In for IIS 7.5
http://go.microsoft.com/?linkid=9670144&clcid=0x409
Demo 4: Configuring an FTP Server with the New Administration Interface
http://go.microsoft.com/?linkid=9670145&clcid=0x409
Demo 5: Connecting to Windows 7 Clients Using DirectAccess
http://go.microsoft.com/?linkid=9670146&clcid=0x409
Using the Windows Server 2008 R2 Migration Tools
http://go.microsoft.com/?linkid=9670053&clcid=0x409
Demo 1: Installing Windows Server Migration Tools
http://go.microsoft.com/?linkid=9670147&clcid=0x409
Demo 2: Migrating Active Directory®
http://go.microsoft.com/?linkid=9670148&clcid=0x409
Demo 3: Migrating DNS Servers
http://go.microsoft.com/?linkid=9670149&clcid=0x409
Demo 4: Migrating IP Settings
http://go.microsoft.com/?linkid=9670150&clcid=0x409
Demo 5: Migrating DHCP Servers
http://go.microsoft.com/?linkid=9670151&clcid=0x409
Demo 6: Migrating Local Users and Groups
http://go.microsoft.com/?linkid=9670152&clcid=0x409
Demo 7: Migrating File Servers
http://go.microsoft.com/?linkid=9670153&clcid=0x409
Demo 8: Migrating Print Servers
http://go.microsoft.com/?linkid=9670154&clcid=0x409
2011/02/02
Generating Passwords with Powershell
#
#######################################################################
# FUNCTION NAME: New-Password
#
# See USAGE() function for docs.
#
# WRITTEN BY: Derek Mangrum
#
# REVISION HISTORY:
# 2008-10-23 : Initial version
#######################################################################
function New-Password
{
param
(
[int]$length,
[switch]$lowerCase,
[switch]$upperCase,
[switch]$numbers,
[switch]$specialChars
)
BEGIN
{
# Usage Instructions
function Usage()
{
Write-Host ''
Write-Host 'FUNCTION NAME: New-Password' -ForegroundColor White
Write-Host ''
Write-Host 'USAGE'
Write-Host ' New-Password -length 10 -upperCase -lowerCase -numbers'
Write-Host ' New-Password -length 10 -specialChars'
Write-Host ' New-Password -le 10 -lo -u -n -s'
Write-Host ' New-Password'
Write-Host ''
Write-Host 'DESCRIPTION:'
Write-Host ' Generates a random password of a given length (-length parameter)'
Write-Host ' comprised of at least one character from each subset provided'
Write-Host ' as a switch parameter.'
Write-Host ''
Write-Host 'AVAILABLE SWITCHES:'
Write-Host ' -lowerCase : include all lower case letters'
Write-Host ' -upperCase : include all upper case letters'
Write-Host ' -numbers : include 0-9'
Write-Host ' -specialChars : include the following- !@#$%^&*()_+-={}[]<>'
Write-Host ''
Write-Host 'REQUIREMENTS:'
Write-Host ' You must provide the -length (four or greater) and at least one character switch'
Write-Host ''
}
function generate_password
{
if ($lowerCase)
{
$charsToUse += $lCase
$regexExp += "(?=.*[$lCase])"
}
if ($upperCase)
{
$charsToUse += $uCase
$regexExp += "(?=.*[$uCase])"
}
if ($numbers)
{
$charsToUse += $nums
$regexExp += "(?=.*[$nums])"
}
if ($specialChars)
{
$charsToUse += $specChars
$regexExp += "(?=.*[\W])"
}
$test = [regex]$regexExp
$rnd = New-Object System.Random
do
{
$pw = $null
for ($i = 0 ; $i -lt $length ; $i++)
{
$pw += $charsToUse[($rnd.Next(0,$charsToUse.Length))]
Start-Sleep -milliseconds 20
}
}
until ($pw -match $test)
return $pw
}
# Displays help
if (($Args[0] -eq "-?") -or ($Args[0] -eq "-help"))
{
Usage
break
}
else
{
$lCase = 'abcdefghijklmnopqrstuvwxyz'
$uCase = $lCase.ToUpper()
$nums = '1234567890'
$specChars = '!@#$%^&*()_+-={}[]<>'
}
}
PROCESS
{
if (($length -ge 4) -and ($lowerCase -or $upperCase -or $numbers -or $specialChars))
{
$newPassword = generate_password
}
else
{
Usage
break
}
$newPassword
}
END
{
}
}
Use the script like this:
New-Password -length 7 -lowerCase -upperCase -numbers -specialChars
2011/01/31
Powershell - SYDI - Convert all my XML to DOC Files
In my case i collected all the information into XML Files. Then i needed to convert those XML files to DOC files.
#
# ==============================================================================================
#
# Microsoft PowerShell Source File
#
# NAME: SYDI-Convert_XML_files_To_DOC.ps1
#
# AUTHOR: fxavier.cat@gmail.com
# DATE : 1/26/2011
#
# COMMENT: Convert all the XML files in the folder XML to a DOC file and output in DOC folder
#
# ==============================================================================================
###################
## CONFIGURATION ##
###################
$PathToSYDI = "c:\sydi"
$PathToXML = "c:\sydi\xml"
$PathToDOC = "c:\sydi\doc"
$PathToTOOLS = "c:\sydi\tools"
$WaitTimeSecs = 10
############
## SCRIPT ##
############
# Get listing of XML files
$XMLList=gci $PathToXML
# Get the count of files in $PathToXML
$count_xml = gci $PathToXML\ | measure
$TotalFilesXML=$count_xml.count
# Create a counter to show in the loop (foreach)
$counter = 0
# Show the count of files
Write-Host "Total XML Files:" $TotalFilesXML
# Start the Loop
Write-Host "Start - XML to DOC"
gci $PathToXML\|sort | `
foreach {
$counter++
$fichier = $_.name
$fichierBasename = $_.basename
$fichierCreatedOnYEAR=$_.lastwritetime.Year
$fichierCreatedOnMONTH=$_.lastwritetime.Month
$fichierCreatedOnDAY=$_.creationtime.Day
Write-Host "# $counter of $TotalFilesXML"
Write-Host "Current file: $fichier"
Write-Host "XML File Creation time of the $fichier is $fichierCreatedOnYEAR-$fichierCreatedOnMONTH-$fichierCreatedOnDAY"
# Run SYDI
cscript "$PathToTOOLS\ss-xml2word.vbs" "-d" "-x$PathToXML\$fichier" "-l$PathToTOOLS\lang_english.xml" "-o$PathToDOC\$fichierBasename-$fichierCreatedOnYEAR-$fichierCreatedOnMONTH-$fichierCreatedOnDAY.doc"
Write-Host "DOC File saved as: "+"$PathToDOC\$fichierBasename-$fichierCreatedOnYEAR-$fichierCreatedOnMONTH-$fichierCreatedOnDAY.doc"
# Show again the counter
Write-Host "#$counter of $TotalFilesXML"
# Timeout to make sure the sydi is done.
Write-Host "Next in $WaitTimeSecs secs..."
Start-Sleep $WaitTimeSecs
# Kill winword to make sure the script dont launch multiple process
Write-Host "Killing process winword.exe"
Stop-Process -Name "winword" -Force
}
# Count DOC Files
$count_DOC = gci $PathToDOC\ | measure
$TotalFilesDOC=$count_DOC.count
# Get listing of DOC Files
$DOCList=gci $PathToDOC
Write-Host "Total DOC Files:"$TotalFilesDOC
Write-Host "Total XML Files:"$TotalFilesXML