25 Sep 2009 @ 20:40 

A question was posted on a forum today, on how to find out how many active sessions was on a Server 2008 Terminal Server, the poster said that on his 2003 Terminal Server he could query the WMI class Win32_PerfFormattedData_TermService_TerminalServices, but that did not work on Server 2008.

So I thought I would give it a shot and see if I could find it, I assumed that it was replaced by a new class, so I had to search the different WMI classes to find the new one.

# Find WMI TS Class
#CTN
Get-WMIObject -ComputerName "TSServer"  -List  *term* |   % {($_.Properties | where {$_.Name -like "*session*"}) } | ft name, Origin

What I do here is tell Get-Wmiobject to list all wmi classes on server “TSServer” that contains the word “term” (I guessed it would be called something with terminal services still)

The foreach of the classes returned I check if it has a property that contains the word “session”, and just output that as a table, resulting in this on a Server 2008 R2 running Remote Desktop Services.

Name Origin
—- ——
DisconnectedSessions Win32_TerminalService
TotalSessions Win32_TerminalService
ActiveSessions Win32_PerfFormattedData_LocalSessionManager_TerminalServices
InactiveSessions Win32_PerfFormattedData_LocalSessionManager_TerminalServices
TotalSessions Win32_PerfFormattedData_LocalSessionManager_TerminalServices
ActiveSessions Win32_PerfRawData_LocalSessionManager_TerminalServices
InactiveSessions Win32_PerfRawData_LocalSessionManager_TerminalServices
TotalSessions Win32_PerfRawData_LocalSessionManager_TerminalServices

Of course to be able to do this, I had to know/guess that the class contained “term” and that the property would be named something with “session”

Posted By: Xenophane
Last Edit: 25 Sep 2009 @ 20:40

EmailPermalinkComments (0)
Tags
Categories: Everyday
 23 Sep 2009 @ 21:21 

I was just playing with the Set-ExecutionPolicy cmdlet today, when I noticed that in V2, it is possible to change the execution policy for different scopes, even though you are not running your session using the “Run as administrator”.

Lets say you want to set the executionpolicy to unrestricted for a single powershell process, you can do that using the -scope option like this

Set-ExecutionPolicy -Scope Process Unrestricted

This will prompt you if you want to change the execution policy for your “current” process.

There are 3 different scopes, Process, CurrentUser and LocalMachine, where Localmachine is computer wide setting for all users, this still requires “admin rights” to set.

Posted By: Xenophane
Last Edit: 23 Sep 2009 @ 21:21

EmailPermalinkComments (0)
Tags
Categories: Everyday
 20 Sep 2009 @ 9:40 

There has been some speculation on the web regarding the ADMGS for Server 2008 and 2003, if it would be possible to use it, in an environment without at least one Server 2008 R2.

So I decided to test it, I built a Server 2003 Domain, comprised of a single 2003 R2 Domain Controller, and 1 Windows 7 Enterprise workstation.
I installed Server 2003 into a VM, installed all updates inlcuding SP2, I then ran DCpromo to setup the new domain. When that was complete I downloaded the 2 required patches for 2003, to be able to run ADMGS.
(NDP35SP1-KB969166-x86.exe and 376193_ENU_i386_zip.exe), where the last of the two patches requires registration to download.

When they were installed, I downloaded the ADMGS setup file (Windows5.2-KB968934-x86.exe).
I created a few users, and everything worked fine.

I then built a Windows 7 client, downloaded the RSAT for Win 7 and joined it to the domain. I then ran my Powershell script to enable all RSAT tools on the machine.

The first thing I tried out was the new Active Directory Administrative Center, the new AD manament GUI built on Powershell, it connected to the DC, and I searched for the users I had created, and they showed up **SUCCESS**
I played around with it some more, creating/deleting some users, and everything seemed to work fine, so I tried out the “Active Directory Module for PowerShell”, pulling down some information about users and computers which also worked.

So all in all it seems as if it is not required to have a Server 2008 R2 in you domain/forest in order to use ADWS (Active Directory Web services) in your domain.

So there you have it folks, there are now a full live competitor to the Quest AD cmdlets, which have been around for a while and have let you manage you 2003 AD… Let the fight begin :)

Posted By: Xenophane
Last Edit: 20 Sep 2009 @ 09:42

EmailPermalinkComments (1)
Tags
Tags: , ,
Categories: Tech Stuff
 19 Sep 2009 @ 16:45 

Yesterday I was doing some maintenance on a machine at work, and when I looked in device manager, i saw that it was a Hyper-V guest machine, and I asked a few colleagues about it, because I was pretty sure that we didn’t have any machines running Hyper-V.. So I needed to find out which machine, so I wrote a quick and dirty PowerShell script to find it.

First off I knew that it had to be a Windows 2008 machine, that boiled down the possible machines quite a lot.

Here is what I did

Get-QADComputer | Where {$_.OSname -match "2008"} | % { Get-Service -ComputerName $_.Name} | where {$_.Displayname -match "hyper"} |  select  Machinename, Displayname

I get all computers that are Windows server 2008, and for each server 2008, I look for services containing the word “hyper”.
This is not a very efficient search, but a quick and dirty way to find the info that I needed.

—-EDIT—–

Kirk Munro pointed out to me that Hyper-V actually registers a SCP (Service Connection Point) in AD, so instead of querying all the machines, you can just query the list of SCP’s in AD instead, which is much more efficient.

Get-QADObject -Name 'Microsoft Hyper-V' -Type serviceConnectionPoint | Get-QADComputer -Identity {$_.ParentContainerDN}
Posted By: Xenophane
Last Edit: 25 Sep 2009 @ 20:38

EmailPermalinkComments (0)
Tags
Tags:
Categories: Tech Stuff
 14 Sep 2009 @ 13:41 

I have just upgraded my machines to Windows 7 RTM, before I did the reinstall I did full backup of my old Vista machines, of course I figured out that I had not gotten all the files out of the Vista machines before I upgraded, So I had to restore some files from the resulting .vhd backup images. But when I started Windows 7 restore, it did not recognize the backup folders.. So I thought I would just mount the vhd backup files manually, by going into Computer Management -> Disk management. But after having done that a few times, I thought it was too much hassle, so I decided to write a little PowerShell script to mount the vhd files for me.

# PowerShell function to create a script file for diskpart
# and the execute diskpart with the scriptfile
function Mount-Vhd {param([String]$InputFile)
"SELECT VDISK FILE=""$InputFile""" + "`r`n" + "ATTACH VDISK" | Out-File $env:TEMP\Mountvhd.txt -Encoding "ASCII"
Invoke-Expression -Command "Diskpart.exe /s $env:TEMP\Mountvhd.txt"
}
Mount-Vhd $args[0]

The above script has to be saved as “Mount-vhd.ps1″

But I wanted something even more simple, I just wanted to be able to right-click a .vhd file and choose open, so I created this little .reg file, that will allow you to right click a .vhd file and choose open.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.vhd]

[HKEY_CLASSES_ROOT\.vhd\shell]
@=”Open VHD”

[HKEY_CLASSES_ROOT\.vhd\shell\Open VHD]
@=”Open &VHD”

[HKEY_CLASSES_ROOT\.vhd\shell\Open VHD\command]
@=hex(2):22,00,43,00,3a,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,5c,\
00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,69,00,6e,00,\
64,00,6f,00,77,00,73,00,50,00,6f,00,77,00,65,00,72,00,53,00,68,00,65,00,6c,\
00,6c,00,5c,00,76,00,31,00,2e,00,30,00,5c,00,70,00,6f,00,77,00,65,00,72,00,\
73,00,68,00,65,00,6c,00,6c,00,2e,00,65,00,78,00,65,00,22,00,20,00,2d,00,57,\
00,69,00,6e,00,64,00,6f,00,77,00,53,00,74,00,79,00,6c,00,65,00,20,00,68,00,\
69,00,64,00,64,00,65,00,6e,00,20,00,2d,00,66,00,69,00,6c,00,65,00,20,00,22,\
00,63,00,3a,00,5c,00,74,00,6f,00,6f,00,6c,00,73,00,5c,00,4d,00,6f,00,75,00,\
6e,00,74,00,2d,00,76,00,68,00,64,00,2e,00,70,00,73,00,31,00,22,00,20,00,22,\
00,25,00,31,00,22,00,00,00

When you import the file, all the hex values are converted back to ascii chars, which you can see under [HKEY_CLASSES_ROOT\.vhd\shell\Open VHD\command] of course

Here is what will be written:

“C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” -WindowStyle hidden -file “c:\tools\Mount-vhd.ps1″ “%1″

As you can see it expects the Mount-Vhd powershell file to be located in C:\tools\ in order to work. I have so far not been able to make it work, without referencing the file directly.

But when you have imported the .reg file, you can just navigate to [HKEY_CLASSES_ROOT\.vhd\shell\Open VHD\command] and change the path to anything you like.

You can download both files from here: http://xipher.dk/Tools/ImportVHDsettings.zip

Posted By: Xenophane
Last Edit: 14 Sep 2009 @ 13:44

EmailPermalinkComments (0)
Tags
Tags: , ,
Categories: Tech Stuff
 04 Sep 2009 @ 23:33 

I finally found some time today to upgrade my primary work machine to Windows 7 RTM (Yeah). Since I do a lot of system administration one of the first things I put on there was my Powershell tools and RSAT. I went and got the RSAT tools from the MS website, I install it, go into “turn on/off Windows features” menu and click the to level check for RemoteAdministrationTools, in the hope that it would select all the admin tools, but no!
I have to check each and everyone..

Then I remembered a while back on the Minasi forum, it was discussed if there was an easier way, and Mark said: “There is probably a one line DISM command for that”, so I took a look at DISM, and found that to my (albeit limited) knowledge there was no way to install all the tools at once.

So I thought to myself, well I guess I have to do it in powershell then, so I started out writing a small script to enable all the admin tools one by one.

Then suddenly Marks words sprung to mind again, “there is probably a DISM oneliner to do this), so I rewrote my little script to a oneliner, here is what I ended up with:

#
#Enable RSAT features
dism /online /get-features | Select-String -Pattern remote* | %{$Exec = "dism.exe /online /enable-feature /featurename:RemoteServerAdministrationTools /featurename:" + ($_).ToString().Replace('Feature Name : ',''); Invoke-expression $Exec}

Dism requires admin permissions, so you need to run this elevated.

Here is what it does:

dism /online /get-features

Uses DISM to retrieve a list of available “features”
That list is then piped into a Select-string statement, that selects all that contain the string “Remote*”, which luckily all the admin tools does :)

Each of the selected strings are then “piped along the pipeline” in the next command, which is a bit more complicated:

%{$Exec = "dism.exe /online /enable-feature /featurename:RemoteServerAdministrationTools /featurename:" + ($_).ToString().Replace('Feature Name : ',''); Invoke-expression $Exec}

% = foreach, so foreach string the Select-String returns, I start to build the $exec variable, the first part of the variable is just text "dism.exe /online /enable-feature /featurename:RemoteServerAdministrationTools /featurename:" this next part is where the feature name is extracted: ($_).ToString().Replace(‘Feature Name : ‘,”). What it does is it converts the output from Select_String ($_) into a string, on that string it replaces “‘Feature Name : “, with nothing “”, so that the $exec variable will end up containing the the initial string, plus the name of the “current” “feature” in the pipeline, giving a full command that can be executed, something like this dism.exe /online /enable-feature /featurename:RemoteServerAdministrationTools /featurename:RemoteServerAdministrationTools-Roles-AD. Then it is “executed” by the Invoke-expression $exec.

So since what I do is just creating a regular commandline expression and executing it, there is not reason why I cannot just export the result to a batch file, which I can edit and run.

#
#Output DISM RSAT commands to file
dism /online /get-features | Select-String -Pattern remote* | %{$Exec = "dism.exe /online /enable-feature /featurename:RemoteServerAdministrationTools /featurename:" + ($_).ToString().Replace('Feature Name : ','');Out-File -InputObject  $Exec -FilePath c:\test.bat}

Hope this was usefull

Posted By: Xenophane
Last Edit: 04 Sep 2009 @ 23:35

EmailPermalinkComments (0)
Tags
Tags: , ,
Categories: Everyday

 Last 50 Posts
 Back
Change Theme...
  • Users » 159
  • Posts/Pages » 101
  • Comments » 73
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

Links



    No Child Pages.

Books



    No Child Pages.

Ønsker



    No Child Pages.

CV



    No Child Pages.