piątek, 7 września 2012

ADUC properties – Home Directory folder mapped on the letter “B”

As you can notice, when you try to map “Home Directory” folder on the letter “B”, there is no possibility for doing this from ADUC’s user properties window:


The resolution for this is making that change using powershell:

Set-QADUser test.test -HomeDrive “B:”

Or using dsmod:

dsmod user “CN=Test Test,OU=people,DN=domain,DN=pl” -hmdrv “B:”

After that operation, the field that is responsible for “Home Directory” drive will be left blank, despite of that you will be able to see that setting in powershell:



The Home Directory folder should now be mapped on “B” letter.

Powershell / Exchange 2007 – sum in MB of all mailboxes, deleted elements, .edb file and white spaces for a storage group

Some time ago, I had a need to determine some of storage groups parameters from Exchange 2007, that need become more frequent than I thought, and here is that script.

The script wll return those values like in 3th line of it, so there will be: Storage group name, sum of all mailboxes (in megabytes), sum of all deleted items (in megabytes), size of the *.edb database file, and the amount of white space in each storage group.

$data = Get-Date –f "yyyy-MM-dd";
$MailboxServer = "Here enter the name of your mailbox server"
out-file -filepath StorageGroupsReport_$data.txt -append -inputobject "Storage GRoup Name ($elem);Sum for all mailboxes (MB) ($suma);Sum of all deleted elements (MB) ($sumdel);Database file size (MB) ($sumadb);Sum of White Space (MB) ($SG_WS)"

foreach ($elem in Get-MailboxDatabase){
 $elem
 $SG_MB = (Get-Mailbox -ResultSize Unlimited -Database "$elem" |  get-mailboxstatistics  | measure-object totalitemsize -sum)
 $suma = "{0:N2}" -f ($SG_MB.sum / 1MB)

 $SGdel_MB = (Get-Mailbox -ResultSize Unlimited -Database "$elem" |  get-mailboxstatistics  | measure-object totaldeleteditemsize -sum)
 $sumadel = "{0:N2}" -f ($SGdel_MB.sum / 1MB)

 $SGDB_MB = (Get-MailboxDatabase "$elem" | foreach-object {add-member -inputobject $_ -membertype noteproperty -name mailboxdbsizeinGB -value ([math]::Round(([int64](get-wmiobject cim_datafile -computername $_.server -filter ('name=''' + $_.edbfilepath.pathname.replace("\","\\") + '''')).filesize / 1mb),2)) -passthru}  | measure-object mailboxdbsizeinGB -sum)
 $sumadb = "{0:N2}" -f ($SGDB_MB.sum)

 $dt = $elem.name
 $s = (get-eventlog Application -ComputerName $MailboxServer -instanceID 1074136261 -Message "*$dt*" -newest 1 | select -expand message )
 $d = ($s.IndexOf(" megabytes") - $s.IndexOf("`has "))
 $SG_WS = ($s.Substring($s.IndexOf("has "),$d).trim("has "))
 $SG_WS
 out-file -filepath StorageGroupsReport_$data.txt -append -inputobject "$elem;$suma;$sumadel;$sumadb;$SG_WS"
}

http://paweljarosz.wordpress.com/2012/05/30/zabbix-powershell-get-processes-by-pid/

My colleague from work wanted me to monitor memory utilization by each oracle processes – and connect them to the appropriate service. ZABBIX let us to monitor procesess, but the problem is, as far as I know, we can monitor them by name, not by the PID, and everything will be all right if those processes haven’t got the same name “oracle.exe”…

So from that point I knew I should use the “UserParamater” to get them. Additional issue, and very obvious, is that those PIDs are changing with every OS reboot. The solution is a script in powershell that you can run after each reboot, for ex. in “task scheduler”. It will create/update *.vbs scripts that are responsible for gathering the data about the memory utilization, of course zabbix_agentd.conf has to contain lines like:

UserParameter=GetMemoryVCS02DB,%systemroot%\system32\cscript.exe /nologo c:\zabbix\OracleServiceVCS02DB.vbs

to refer to those scripts. Script is very simple and looks like this:

$services = (gwmi WIn32_Service | where {$_.name -match "OracleService"})

foreach ($service in $services) {
$f = $service.name + ".vbs"
$p = $service.ProcessID
If ($f) {Clear-Content $f}
out-file -filepath $f -append -inputobject 'Set objWMI = GetObject("winmgmts:\\.\root\cimv2")'
out-file -filepath $f -append -inputobject "Set colObjects = objWMI.ExecQuery(`"SELECT * FROM Win32_Process WHERE ProcessID =`'$p`'`")"
out-file -filepath $f -append -inputobject 'For Each Item in colObjects'
out-file -filepath $f -append -inputobject 'wScript.Echo Item.WorkingSetSize'
out-file -filepath $f -append -inputobject 'Next'
}

ADUC properties – Displaying and changing user’s hidden properties with powershell

It is not so obvious how to display/change some properties like “ipphone”, because they are not shown in Get-QADUser.

To display hidden properties of user like”ipphone” number we can use the command:

get-qaduser user.name -IncludeAllProperties ipphone

Changing this property we can do like this:

set-qaduser user.name -objectAttributes @{ipphone=”666″}

SCCM – Different data in Resource Explorer and Add/Remore Programs while running report

Recently my colleague tried to make a report with workstations that have particular version of software – Adobe Reader. But he meet a problem because in report with Adobe Reader 9, he had workstations that definatelly had version 10, the same with version 8 – there was completely mess, as he was checking the Add/Remove Programs on the workstation it appeared it has some other version.

I found it indeed very weird,and tried to solve. By making directly queries on the database I noticed that indeed v_Add_Remove_Programs (name in SCCM report ->SMS_G_System_Add_Remove_Programs) shows old stuff – 9 version of Adobe Reader, but the database view v_SoftwareProducts (name in SCCM report -> SMS_G_System_SoftwareProducts) shows correct data – version there was 10. That was even double weird for me :) but after some time with google I have finally found the explanation.

The “Add/Remove Programs” stuff in updated by… “Hardware Inventory” client task, while “Software Products” as you can figure it out from it’s name – by “Software Inventory task”.

My hardware inventory period was set to one week, while software for 1 day. Lost for this almoust two days…

Powershell / ZABBIX - how to determine if there are any emails in a particular mailbox folder for longer than some certain time.

Recently I had to make a script for ZABBIX user parameter, that will look if mailbox folder contains a email message that has been received over some time ago.

I haven't been doing this before so I was really astonished that I can receive that kind of information with Powershell. Unfortunatelly as far as I know, I can determine only the time of the oldest message - but this works for me, the next step will be to get number of all messages that are actually in folder for above than some certain time - I think I would need outlook object to do that. But at this time I have something like this:

$SystemDate = (Get-Date)
$MailboxStatistics = (Get-MailboxFolderStatistics -IncludeOldestAndNewestItems -identity {MAILBOX} | where {$_.Name -match "{MAILBOX_FOLDER}"})
$OldestItemReceiveDate = ($MailboxStatistics.OldestItemReceivedDate)
if ($OldestItemReceiveDate){
$OldestItemReceiveDateLocalTime = get-date ($OldestItemReceiveDate).tolocaltime()
    $SystemAndLastMessageDateDifference = ($SystemDate - $OldestItemReceiveDateLocalTime)
    if ($SystemAndLastMessageDateDifference.TotalMinutes -gt "10") {
    $MailboxStatistics.ItemsInFolder-1
    } else {Write-Host "0"}
} else {
Write-Host "0"
}

 Thge script will check if there is en email in certain folder in mailbox, that is being there for more than 10 minutes, if it is true, it will get amount of email messages that are in the folder at the time. Unfortunatelly as I said it will return also the emails that are not there for 10 minutes, but we are sure that there is at least one :)