Tuesday, April 21, 2015

removing windows 2012 data deduplication volume

thanks to nickwhittome.com/2014/10/01/disabling-data-deduplication-on-windows-server-2012r2

#The unoptimise command
start-dedupjob -Volume E:   -Type Unoptimization
#Check the status
get-dedupjob

Then...

#Clean up the Garbage
start-dedupjob -Volume
E: -Type GarbageCollection
#Check the status
get-dedupjob


Then...
 
Disable-DedupVolume -Volume E:

Adobe Reader 10 - Access Denied opening PDF - solved

Some Operational team members moved some data to a Windows 2012 R2 server.
The Citrix Environment is currently in a 'change freeze' and was running 10.0.1.0 of adobe readerX.


When a pdf was opened from network share "access denied"
It could be fixed by untick protected mode.. but then we are unprotected right.

Note: Upgrading the Adobe reader also fixed this issue but 'Change Freeze'

so




Root Cause : Citrix version of Adobe Reader PDF is not trusting any de-duplicated pdf files as they have been “modified”

Process to replicate

  1. robocopy  "E:\Data\Group" E:\temp   *.pdf /s  /move
  2. robocopy   "E:\temp" "E:\Data\Group"   E *.pdf /s /move
  3. [pdf file attribute was A]
  4. Forced Dedup Job - Start-DedupJob E: -Type Optimization 
    (note our server was set to MinimumFileAgeDays 0)
  5. [pdf file attribute was APL]


so either



Set-DedupVolume –Volume E: -ExcludeFiletype pdf
 or
 Just disabled dedup on this volume.

/thx

Thursday, April 16, 2015

Active Directory ProxyAddress Email Addresses SMTP Extract with powershell

Bit of fun with extracting SMTP secondary addresses from user account.

$user=get-aduser testuser -prop,proxyAddresses

$user|select samaccountname,@{Name=”AdditionalAddresses”;Expression={($_.proxyAddresses| Foreach-object {$_.split([environment]::NewLine)} | Where-Object {$_ -match “smtp”} | ForEach-Object {$_.substring(5)}) -join "|"}}


so..

#
#Export Detailed AD Membership info
#dump a full member list text file only once per day
#

$outputfile = $savepath + "\" + $dayofweek + "_theuserlist.xlsx"
del $outputfile
$allpandas = get-aduser -filter {extensionattribute5 -eq "Pandas"}  -Properties displayname,title,company,department,lastlogondate,physicalDeliveryOfficeName,proxyAddresses,EmailAddress
$allpandas = $allpandas|select samaccountname,givenname,surname,displayname,title,company,department,UserPrincipalName,physicalDeliveryOfficeName,lastlogondate,EmailAddress,@{Name=”AdditionalAddresses”;Expression={($_.proxyAddresses| Foreach-object {$_.split([environment]::NewLine)} | Where-Object {$_ -match “smtp”} | ForEach-Object {$_.substring(5)}) -join "|"}}
$allpandas | C:\scripts\Export-XLSX.ps1 -Path $outputfile -WorkSheetName 'pandas'

Monday, March 23, 2015

force a machine password change


nltest.exe /sc_change_pwd:mydomain.corp.mycompany.com


now with more info...
http://blogs.msdn.com/b/sudhakan/archive/2010/01/07/experimenting-with-windows-machine-account-passwords-and-vm-snapshots.aspx

Friday, March 20, 2015

Audt Drive Mappings - Group Policy Objects with Powershell

We have bunch of GPOs that perform drive mappings
Unfortunately another team normal does the site work.

so after a little while with servers moving all over the place servers disappear but GPO still had mappings and groups . RAGE

so a bit of powershell to check all the paths

diving into the get-gpo was interesting.

got stumped on test-path when access is denied for a little while until worked out the errorvariable was the way around it.

http://pastebin.com/VvgZpWnA

Friday, March 13, 2015

powershell html table color

Came across some code to change arrays into some nice html code.
has the ability to colour code cells.

#
# $finalrepinfo is array
#
$html = $finalRepInfo|ConvertTo-Html -Fragment
 
$xml = [xml]$html

$attr = $xml.CreateAttribute("id")
$attr.Value='diskTbl'
$xml.table.Attributes.Append($attr)


$rows=$xml.table.selectNodes('//tr')
for($i=1;$i -lt $rows.count; $i++){
    $value=$rows.Item($i).LastChild.'#text'
    if($value -ne $null){
       $attr=$xml.CreateAttribute('style')
       $attr.Value='background-color: red;'
       [void]$rows.Item($i).Attributes.Append($attr)
    }
  
    else {
       $value
       $attr=$xml.CreateAttribute('style')
       $attr.Value='background-color: green;'
       [void]$rows.Item($i).Attributes.Append($attr)
    }
}

#embed a CSS stylesheet in the html header
$html=$xml.OuterXml|Out-String
$style='<style type=text/css>#diskTbl { background-color: white; }
td, th { border:1px solid black; border-collapse:collapse; }
th { color:white; background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px } table { margin-left:50px; }</style>'

ConvertTo-Html -head $style -body $html -Title "Replication Report"|Out-File ReplicationReport.htm


Friday, March 6, 2015

Microsoft Forefront Eventlog | Powershell

thru complex number of reasons... need to monitor forefront via eventlogs - dont have centralised reporting.

1.could of setup alerts on each box to email when a virus detections
2.powershell to check eventlogs and do stuff with it.

had issue with eventlog culture on non powershell4 box.

#
# Virus Detections Last 1 days
#

$LogEntries =@()
$daysAgo = (get-date) - (new-timespan -day 1)

# BugFix for PS3 and anything other than en-us
$orgCulture = Get-Culture
[System.Threading.Thread]::CurrentThread.CurrentCulture = New-Object "System.Globalization.CultureInfo" "en-US"

#
# Target
#
$ou='OU=MOE Servers,DC=lc,DC=local'
$computers=Get-ADComputer -Filter * -SearchBase $ou


foreach ($server in $computers) {
$report=Get-WinEvent -FilterHashtable @{logname='system'; id=1006; ProviderName='FCSAM';StartTime=$daysAgo} -computername $server.dnshostname -ErrorAction SilentlyContinue

    if ($report){
    foreach ($panda in $report){
        $Obj = New-Object -TypeName PsObject
        $Obj | Add-Member -membertype noteproperty -name Server -value ($server.DNSHostName)
        $Obj | Add-Member -membertype noteproperty -name TimeCreated -value ($panda.timecreated)

            foreach ($jeff in (($panda.message).Split("`r"))){
            if ($jeff -match "Name:"){$output=$jeff}
            if ($jeff -match "Severity:"){$output+=$jeff}
             }
        $Obj | Add-Member -membertype noteproperty -name Message -value ($output.Trim())
        $LogEntries += $Obj
    }
#Clear 
$report=$null
$output=$null
}

}

#
# Switch back to Aus
#
[System.Threading.Thread]::CurrentThread.CurrentCulture = New-Object "System.Globalization.CultureInfo" "en-AU"

$LogEntries | sort timecreated -Descending

#
# then do stuff like export to webserver or..
#