Skip to main content

Posts

Get User connections to a share

I have always put this one in the "I'll get round to it" pile.  Today, I have finally got round to it! You can quite easily determine who is connected to a Windows Server by going to Computer Manager and choosing shared folders - sessions.  You can also see how many people are connected to a share by going to Computer Manager and choosing shared folders - shares.  What i want to know is WHO is connected to each share.  I have had quite a big reason to do this recently and so I have finally got round to creating a powershell 2 function to do precicely that! It will accept 2 parameters, a servername and an optional sharename to return only the connections from a particular share.  Regards Adam function get-shareConnection { #generate the help file <# .SYNOPSIS Get the current users that are connected to shares on a server .DESCRIPTION Get the current users that are connected to shares on a server. This can be filtered to a specif...

Nice post on arrays

Hi I've justhad a comment from a colleague that i haven't put anything up here for a while (thanks Dimce!), which is very true - i can only hold my head in shame! Since that comment, i have found a very nice (albiet from a few years back) article about arrays from Bruce Payette http://blogs.msdn.com/b/powershell/archive/2007/01/23/array-literals-in-powershell.aspx?wa=wsignin1.0 this just says to me that for however long you use powershell, there is always something more to learn! cheers Adam

AD Bitlocker Recovery with Quest tools

It has been a while since I have posted anything, mainly due to changing jobs and the time spent with my ever growing family.  This is not to say that I have not been keeping up with scripting development...far from it! I had an interesting one today where a request came in for the following : “I need the bitlocker recovery password for a deleted computer object” As my current environment does not support the AD cmdlets, I looked to the quest tool set and was pleasantly surprised. Here is what I came up with, commented in line... #for easy editing, define the computername that has been deleted $compname = "ABC12345" #search AD including Deleted objects (-tombstone) for recovery information objects and filter where the last known parent contains the computer name. Then just return the password $recoverykey = Get-QADObject -Tombstone -Type "msFVE-RecoveryInformation" -SizeLimit 0 -Includedproperties msFVE-RecoveryPassword -SearchRoot "CN=Deleted Objects...

Powergui.org

I have recently been contributing to powergui.org, an RSS feed of my posts follows: feed://powergui.org/rss/rssmessages.jspa?categoryID=55&rssUsername=adamstone  when ever searching for answers, powergui.org always seemed to come up in my google results and has proven a good resource for powershell answers.  Hopefully, I can contribute something back! cheers Adam

Enabling and Using Windows 2008 R2 AD Recycle Bin

I’ve just had a look at how to use the ad recycle bin... and guess what, you need PowerShell to use it! Once you are running at R2 forest functional level, you need to enable the recycle bin... Get-ADOptionalFeature -filter {name -eq "Recycle Bin Feature"}} | Enable-ADOptionalFeature -scope ForestOrConfigurationSet Once that is done, you can delete an object safe in the knowledge that it will be available for full restore. so, how do we restore it? get-adobject -filter {displayname -eq "Adam Stone"} -IncludeDeletedObjects | Restore-ADObject -TargetPath "cn=users,dc=domain,dc=com" It's not the way I imagined the feature will be implemented, but an improvement on the previous restore process.  Look out for a future post building this into a function!

Export Hash Tables to CSV - Powershell V2

I wrote about hash tables a while back in regards to counting OS types. The one thing I didn't lookinto back then was how to export the information to CSV. Easy, I hear you cry - just use export-csv!  Not quite as easy as you would imagine. The main thing to tackle is the fact that Hash Tables are not objects as we would usually consider them.  If you run get-member on a hash table you get the following properties : Count IsFixedSize IsReadOnly IsSynchronized Keys SyncRoot Values What is required is to create an object based on the hash table prior to exporting. Lets create a similar hash table to the one found in my previous post : $complist = get-ADcomputer -filter {enabled -eq $true} -properties operatingsystem $OSlist = @{} $complist | % {try {$OSlist.$($_.operatingsystem) ++}catch{$OSlist.None ++}} Export this to CSV and you get : PS U:\> $OSlist | Export-Csv "OScount1.csv" -NoTypeInformation PS U:\> type .\OScount1.csv "IsReadOnly",...

compare-object in Powershell - comparing mulitple values

I'm starting to use compare-object more and more, and one thing I noticed, is that you can compare 2 objects based on multiple attributes. here is how it is constructed... Compare-Object -ReferenceObject $object1 -DifferenceObject $object2 -Property a,b,c,d,e If a,b,c and d are the same, but e is different, compare object will return a difference. In the following example, I use "-eq $null" as a check because by default compare-object returns $null if the objects are the same. #create an array of objects to check against $collection = @() foreach ($entry in ("aaaaa","bbbbb","ccccc","ddddd")){    $store = "" | select "a","b","c","d","e"    $store.a = $entry*1    $store.b = $entry*2    $store.c = $entry*3    $store.d = $entry*4    $store.e = $entry*5    $collection += $store } #create an object similar to those in the array $object = "" | select ...