piątek, 19 października 2012

WSUS and Digital Signatures on file C:\Windows\SoftwareDistribution\SelfUpdate\wuident.cab are not trusted: Error 0x800b0001

I have recently met a problem that I have been reciving 0 updates on my machines that were connected to one of WSUS servers. After analisys it appeared that despite of sucesfull synchronization there are some problems with it. As far as I know the best solution for this is reinstalling the WSUS server.

After doing this I statring to receive an error:

Digital Signatures on file C:\Windows\SoftwareDistribution\SelfUpdate\wuident.cab are not trusted: Error 0x800b0001

As I read in the mighty powerfull internet (http://blog.jamzarwebdesign.com.au/), I have to install one update (2720211) to  repair this issue.

I have downloaded this update, I opened the WSUS server on full screen, and I have noticed that in right low corner I have nitification baloon with exactly that update... I have installed it, restart the server, run on the client: wuauclt /resetauthorization /detectnow and everything were ok :D

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 :)

piątek, 31 sierpnia 2012

Lately I meet such a problem, on which I was struggling for a week and couldn't find any solution.

Lady want to edit an excel file, to add some emails there and after clicking on a magical button those contacts should be imported to an Exchange distribution list.

My solution was to make a website written in PHP, that with use of might "shell_exec" will run Powershell script, which will:

1. Connect and read the *.xlsx file

2. remove all mail contacts that are mentioned in clicked distribution list,

3. Add mail contacts to exchange and associate them to appropriate distribution list.

4. Report the status on the operation

I was testing the script locally, I mean, I was simply running it from Powershell console, dealing with error handling and other stuff, the user interface has been left for the last stage of the project. As the script started to work properly the time has come and I have executed the query from PHP - just as I used to do.

The result was unexpected, because I have received.. zero, null, nothing, not even a single error! Just imagine how dramatic that moment has been! :)

So I have done what real detective should done - I was started to debug the script line by line (those main problematic lines are below), and what have appeared, was that line 3 - displaying my object - was correct, because from Powershell I was receiving:

 


And from PHP:




1. $ExcelDocumentPath = "C:\wamp\www\mail_contact_base.xlsx"

2. $ExcelDocument = New-Object -ComObject "Excel.Application"

3. $ExcelDocument <- here was still ok :)

4. $Workbook = $ExcelDocument.workbooks.open($ExcelDocumentPath) <- here was starting shit :)

5. $Workbook

6. $WorkSheets = $Workbook.Worksheets

Buuuut! The line no. 5 gave me...NULL! Not even something like "0" simply there was black page. So it has appeared that with no doubt I have problem with opening the excel object :/

I have redirected the line to 2>&1 to get something more, and what appeared was:

Exception calling "Open" with "1" argument(s): "Brak aktywnego okna widoku chro nionego." At C:\wamp\www\ps.ps1:4 char:42 + $Workbook = $ExcelDocument.workbooks.open <<<< ($ExcelDocumentPath) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ComMethodTargetInvocation

It is in mine language, because I couldn't find zero of that error in English, it says about lack of "ProtectedViewWindow Object", my first thought was that I am in big shit...

I have posted that on http://wss.pl forum and one guru gave me link-> http://support.microsoft.com/default.aspx?scid=kb;EN-US;257757 saying that it would be as hard as I thought or harder :|

I have clicked from side to side trust options in office on that server, nothing helped. So I thought that I will reinstall MS Office application, the server was x64 and the Office was x32, so I thought this is the issue.

After reinstalling I have received another error - about wrong locale - from Powershell and from PHP:

 "Exception calling "Open" with "1" argument(s): "Old format or invalid type....blah blah stuff and other shit here"

But the languages were ok, so I was kind of missing my old error, and I have reinstalled MS Office once again for the same as it was - x32.

After that operation - reinstalling MS Office - the script was running perfectly from Powershell - just as it was before, but in PHP I was receiving..the lack of privileges - no access to the file- deeeeeep shiiit.

I was near becoming insane, it was the last day for finishing that project in, let's say, first work version, and I had nothing. So I started to ask uncle Google, what to do, I still wanted to have my old "lack of ProtectedViewWindow Object" error.

Surprisingly I have found this:

http://stackoverflow.com/questions/5516221/excel-application-not-working-in-Powershell-using-sql-job-but-works-from-comman

The guy is saying that I should do this:

    1. Add Directory: C:\Temp
    2. Add Directory: C:\Windows\SysWOW64\config\systemprofile\Desktop

That should fix the problem.


Indeed there was no “temp” directory on a folder neither “desktop”. I have added them, and run the script, and I have received.. NULL. But wait a minute! I have redirected the errors to standard output, so if there is no error on the page.. is it possible!?!?!

Yup, the guy saved my life :) there was no error about "ProtectedViewWindow" more, and the mail contact from Excel file, has showed up in the Exchange and later on the appropriate distribution list J

środa, 22 sierpnia 2012

SCCM – problem during advertise a package to a client, just tmp files.

SCCM, for me personally, will forever remain a bottomless well of endless problems :)
Lately I meet a problem that the package has been distributed to all Distribution Points correctly, but when it came to deliver it to clients, in local cache folder I saw only *.tmp files, all folders were correct, just there was no normal files.
If somebody has met problem like this here is the solution, at least for mine case:

There is a file: C:\Windows\System32\inetsrv\config\applicationHost.config on SCCM server
and you can find there many record like:
<add fileExtension=”.config” allowed=”false” />
Now it is easy to figure out, that the install folder of application I wanted to deploy in cache, contained one file with “.config” extension. As I changed “false” to “true” in that record, all worked like a harm.

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…

wtorek, 21 sierpnia 2012

piątek, 17 sierpnia 2012

Powershell - how to replace word/character in a string.

Recently I was looking for a good way for replacing words in a string, and found this very helpful page with many methods, hope you find it useful :

http://powershell.com/cs/blogs/tobias/archive/2011/04/28/multiple-text-replacement-challenge.aspx