Richard Siddaway

Explore articles and content from this author

Richard Siddaway

128 articles published

1 min read

Finding the domain controller that authenticated you

A question on my blog asked how do you know which domain controller you are running against when you search Active Directory. Unless you explicitly instruct your script to use a specific domain controller it will use the one to which you authenticated.

You can find the DC to which you authenticated with this simple function

function get-logonserver{
$env:LOGONSERVER -replace “\”, ""
}

2 min read

Displaying data from multiple servers as HTML

A forum question regarding retrieving WMI based data from multiple servers and displaying it as HTML was interesting. I would approach it like this

`$servers

=

Get-Content

-Path

C:\scripts\servers.txt

$data

=

@(

)

foreach

(

$server

in

$servers

)

{

$compdata

=

New-Object

-TypeName

PSObject

-Property

@{

Computer

=

$server

Contactable

=

$false

LastBootTime

=

""

AllowTSConnections

=

$false

}

if

(

Test-Connection

-ComputerName

$server

-Quiet

-Count

1

)

{

$compdata

.

Contactable

=

$true

$os

=

Get-WmiObject

-Class

Win32_OperatingSystem

-ComputerName

$server

$compdata

.

LastBootTime

=

$os

.

ConvertToDateTime

(

$os

.

LastBootUpTime

)

$ts

1 min read

Ensuring that parameter values are passed to your function

A question on the forum about a function had me thinking. The user had defined two parameters for the function and then used Read-Host to get the values.

NO

Much better way is to use an advanced function and make the parameters mandatory

`function

Getuserdetails

{

[

CmdletBinding

(

)

]

param

(

[

parameter

(

Mandatory

=

$true

)

]

[string]

$Givenname

,

[

parameter

(

Mandatory

=

$true

)

]

[string]

$Surname

)

Get-ADUser

-properties

telephonenumber

,

office

-Filter

{

(

GivenName

-eq

$Givenname

)

-and

(

Surname

-eq

$Surname

)

}

}

`If you call the function and don"™t give values for the parameters you will be prompted for them

1 min read

UK PowerShell Group sessions for 2013

This is the list of proposed sessions for 2013. It is subject to change depending on circumstances.

All sessions are delivered by Live Meeting on Tuesdays at 7:30 UK time

29 January – PowerShell and Active Directory
26 February – PowerShell Advanced Functions
26 March – PowerShell cmdlets for Hyper-V
30 April – Notes from the PowerShell summit (may be changed)
21 May – Powershell Web Access
25 June – guest speaker PowerShell MVP Max Trinidad
30 July – Lessons from the Scripting Games
27 August – PowerShell eventing engine
24 September – CIM – cmdlets and sessions
29 October – PowerShell and XML
26 November – PowerShell type system – formatting and types files
17 December – PowerShell error handling

1 min read

Renaming a user

I was asked about searching a user name for a string and replacing it so that the object is renamed.

This is a three stage activity. First get the user. Two modify the name. Three rename the object. In active directory the name attribute has the LDAP name of cn but the Microsoft AD cmdlets treta it as name. So we end up with this code:

`$user

=

Get-ADUser

-Filter

{

cn

1 min read

PowerShell Deep Dives

PowerShell Deep Dives is a book put together by the PowerShell community. I"™m editing one of the sections and have contributed some of the chapters. Manning have just started releasing it on their MEAP program. The full book will hopefully be ready in the spring.

Best of all the royalties are being donated to worthwhile cause.

Check it out – http://manning.com/hicks/