Archive for category Scripting

Powershell: The term ‘Get-ADUser’ is not recognized as the name of a cmdlet (SBS 2008)

We have immense power over our servers with Powershell.

There is so much we can do, or in the case of SBS 2008 (Powershell 2), a lot we wish we could do. I am trying to get a lot of info our of an AD in preparation of moving to a new domain controller. None of my AD scripts work. e.g.

  • Get-ADComputer
  • Get-ADUser

I am constantly getting “The term ‘blah’ is not recognized as the name of a cmdlet”.

Grrr.

After lot’s of reading and playing about, I got what I needed. I was able to install Active Directory Web Service on the machine and then use RSAT on a secondary computer.

So what do you do ?

Let’s start with Server 2008 R2 

You need to have installed

  • Active Directory Domain Services
  • Active Directory Module For Windows PowerShell
  • Active Directory Web Services

Run this at the Powershell commandline

>Import-Module ServerManager
>Add-WindowsFeature RSAT-AD-PowerShell
>import-module activedirectory

You should now be ready to go

Server 2008 or 2003

You need to install this hotfix. The links for this are hard to get working as Microsoft released this patch to only those that actually need it. It has not had very wide testing and has not been checked for what else it could break.
https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=2852

Install the Active Directory Management Gateway Service (Active Directory Web Service for Windows Server 2003 and Windows Server 2008)

Install RSAT on another PC (Windows 7, Windows 10 will be fine)

In powershell

>import-module activedirectory

You should now be ready to go

SBS 2008

Trying to install Active Directory Web Service for Windows Server hotfix as per the above outline, fails. You can try the 32 bit or 64 bit version and it will tell you it is not compatible.

You need to have the file NDP35SP1-KB969166-x86.exe, install it and reboot.

(KB 969166)

It will not install. What can you do? If you really need to get this hotfix installed (Warning, it is not fully tested) then here is a work around.

md c:\temp\AD_Management_Web
expand -F:* “Windows6.0-KB968934-x64.msu” c:\temp\AD_Management_Web
cd c:\windows\system32
start pkgmgr.exe /ip /m:c:\temp\AD_Management_Web\Windows6.0-KB968934-x64.cab

Reboot

Install RSAT on another PC (Windows 7, Windows 10 will be fine)

In powershell

>import-module activedirectory

You should now be ready to go

Useful links

http://thehotfixshare.net/board/index.php?autocom=downloads&showfile=20160

https://powershell.org/forums/topic/ad-module-on-sbs-2008/

Tags: , ,

Programmatically alter “Automatically Detect settings” in IE through VBS

I am trying to turn off the “Automatically Detect settings” in the proxy settings in Internet Explorer (IE), using vbscript (vbs).

It is not as easy as you would think. There are loads of forums out there where people are trying to find the answer. I now have working code, for my version of IE in my environment and whilst you need to do your own testing (not on production machines) I want to let the world know how I did it.

The problem is that this tick box is set by the following registry keys

HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings
HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings

The value is binary and whilst reading this with vbs is easy, changing the huge Hex value into something you can save back, is almost impossible. The REG_BINARY in the Regwrite method wants an integer.

The value looks something like this (This has been edited to keep details private).

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections]
“DefaultConnectionSettings”=hex:46,00,00,00,67,38,00,00,03,00,00,00,10,00,00,\
73,74,72,61,2e,63,6f,6d,3b,2a,2e,6a,68,67,2e,6c,6f,63,61,6c,3b,31,39,32,2e,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
73,74,72,61,2e,63,6f,6d,3b,2a,2e,6a,68,67,2e,6c,6f,63,61,6c,3b,31,39,32,2e,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
64,61,74,a2,2c,55,62,09,d5,ce,01,00,00,00,00,00,00,00,00,00,00,00,00,01,00,\
00,00,02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00
“SavedLegacySettings”=hex:46,00,00,00,d1,4f,00,00,03,00,00,00,10,00,00,00,31,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
2e,74,65,6c,73,74,72,61,2e,63,6f,6d,3b,2a,2e,74,69,70,74,2e,74,65,6c,73,74,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
38,2e,32,2e,2a,3b,3c,6c,6f,63,61,6c,3e,00,00,00,00,01,00,00,00,1a,00,00,00,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
74,a2,2c,55,62,09,d5,ce,01,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00

I spent ages reading how the individual offsets changed certain details. I tried to work out how to change certain parts of these values. I also tried to work out how to reset these values back to a default settings.

Lot’s of people are arguing online what each value does. I got to the point where that was all meaningless.

I looked at importing a reg file to solve my problem. Then I had a change of thought. What if I could somehow force something into this key that blanks all settings but the one I want, and then trough code, add back the other values I needed.
If i can find the code I need and if IE rebuilds the rest of the key, this might be possible. I deleted the whole key. Went into IE and unticked just the “Automatically Detect settings” setting.

I then reviewed the registry and noted that the value of that key was now very simple. It was basically “0F”  and the rest of the data was made up of “00”. So, I wrote my vbs code to delete the key, put back “0F” and then wrote the remainder of what I needed into the settings and … it works !

WSHShell.Regdelete “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings”
WSHShell.Regdelete “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings”,&H46,”REG_BINARY”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings”,&H46,”REG_BINARY”

 

The rest of the code was

 

WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable”, 1, “REG_DWORD”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer”, Proxy IP
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride”, “IP addresses or servernanes here;<local>”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\DisablePasswordCaching”, 1, “REG_DWORD”
‘WSHShell.RegWrite “HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel\Autoconfig”, 0, “REG_DWORD”

This now leaves me with “Automatically Detect settings” off, “Use Automatic configuration script” off, “Bypass Proxy for local servers” on, Proxy details all filled in and a bypass list created.

Perfect !

Tags: , ,