Posts made in November, 2010

How to do ‘replaceall’ in VBScript?

Posted by on Nov 13, 2010 in VBScript | 1 comment

As you might know the vbscript replace function does always search only “one round”. Here is an example, what exactly I mean: Lets assume you want to correct the following string by replacing all “double-l’s” by “single-l’s”: str = "Littllllle worllllllld!" The code would be: wscript.echo replace(str, "ll", "l") But everything this line does is replace all existing “ll” by “l”. So lets have a look what’s left – the output is: Litllle worlllld! Why? The original string contained 5 l in Little and 7 l in world....

Read More

How to access WMI namespaces on remote computers that require encryption?

Posted by on Nov 7, 2010 in VBScript, WMI | 0 comments

When you have a look at my vbscript bitlocker post and try to use it on remote machines you may not get any results but an application eventlog entry similar to this one here: Event Source: WinMgmt Event ID: 5605 Access to the […] namespace was denied. The namespace is marked with RequiresEncryption but the client connection was attempted with an authentication level below Pkt_Privacy. Re try the connection using Pkt_Privacy authentication level. When using security related namespaces on remote machines you need to connect to wmi using a higher authentication level: strComputer =...

Read More

How to use environment variables in Powershell?

Posted by on Nov 6, 2010 in Environment, Powershell | 0 comments

Sometimes you need to use an environment variable (eg. username, userprofile, computername, …) in Powershell. The location where environment variables are stored is “env:”. This behaves similar to a hard or flash drive. You can list its content or browse it by using dir env: The output shows all existing environment variables you can use. But how to use them? You can get every environment variable by using the get-content or for short gc cmdlet. $computername = get-content env:computername $username = gc env:username List of environment variables in Windows 7 /...

Read More

How to display active connections and running queries in SQL Server?

Posted by on Nov 6, 2010 in SQL Server, Transact-SQL | 0 comments

This query shows all queries executed at the moment, the session id, status, used cpu time and the execution duration SELECT st.text, r.session_id, r.status, r.command, r.cpu_time, r.total_elapsed_time FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS st The following query shows the number of connections a user has with a database SELECT db_name(dbid) as DatabaseName, count(dbid) as NoOfConnections, loginame as LoginName FROM sys.sysprocesses WHERE dbid > 0 GROUP BY dbid, loginame

Read More

How to read and use the contents of a website from Powershell?

Posted by on Nov 6, 2010 in Powershell | 0 comments

First we need to create a xmlhttp object, similar to what you would do in JavaScript $objXmlHttp = New-Object -ComObject MSXML2.ServerXMLHTTP Use the open method to specify the url, optional username and password. The third parameter (optional) is a boolean indicator of whether the call is asynchronous – the default is true. $objXmlHttp.Open("GET", "http://www.normanbauer.com", $False, "username", "password") $objXmlHttp.Send() Now we can work with the results $content = $objXmlHttp.responseText $status = $objXmlHttp.status $statustext...

Read More