PowerShell 3: Add Multi-line TXT Record to DNS

This had me stumped for about 30 minutes, until I finally worked out the correct syntax to make this all work.

I was looking for a way to create a TXT record on my DNS server. The data though is a multi-line record – and had to be multi-line for the server to understand the response. Single line are easy – but the multi-line really threw me.

The trick is `r`n – this inserts a carriage return and line feed into the string. I was using a apostrophe at first and wondering why it wasn’t working. It isn’t, it is a grave accent, ASCII 96.

So, as an example:

$txtdata = "line1`r`nline2`r`nline3"
Add-DnsServerResourceRecord -ZoneName testdomain.internal -Name MyNewTXTRecord -Txt -DescriptiveText $txtdata

This gives you a record that looks like this in Windows DNS.

PS-DNS

It would appear at the minute that this command limits the length of the DescriptiveText parameter to 255 charactors. This is maximum string length, per line. PowerShell interprets this as the maximum length overall though.

Be the first to like.
Posted in Server 2012 | Leave a comment

Untangle 9.3.2 on Hyper-V 2012

I have just been playing with getting an Untangle (http://www.untangle.com) server up and running on a Windows Server 2012 Hyper-V install. Looking at this as a possible replacement to ISA 2004 on our current Windows SBS 2003 install.

I had read up various articles of problem that have been encountered with network adapters, no mouse and install problems – all of which appeared to be on Hyper-V 2008.

So, I took the jump (server is still in development, so plenty of scope for testing stuff out). I created a VM using the following:

  • 1 processor
  • 768mb RAM (dynamic)
  • 20gb VHDX fixed disk
  • 2 legacy NICs, bound to 2 different VLAN’s through the same virtual switch

Booted it up, and it picked up the install CD straight away. It passed through all of the hardware pre-requisite checks and was installed and at the config screen in about 10 mins.

I was very surprised to find that the mouse worked out of the box – no integration services installed. So, that made installation a touch easier.

Once I had identified which NIC i had assigned to which VLAN, I managed to get it hooked up to the Internet, where it picked up all the appliances. I installed the Lite pack (saved clicking loads of apps).

Now that I was able to get in I decided to see if the VM would support using a standard virtual network adapter, so changed the internal one, and rebooted. And from this, I can confirm that Untangle 9.3.2 does not detect a standard NIC in Hyper-V. So, reverted back, reset the network configuration and we were back online.

I hooked up my PC to the internal VLAN, and was able to get on the Internet, no problem at all. My statistics in Untangle started going up as I spent some time doing some general browsing.

My next challenge is going to be seeing if I can install the Integration Services pack, or if indeed it is actually built in like some distro’s are. Debian is not listed on the MS support guests website, but it can’t hurt trying. Here is a list of the support guest OS on 2012: http://technet.microsoft.com/library/hh831531.aspx

It’s too early to say if performance wise it is any good running on a VM. As it is working, I should imagine I will put it on test for a couple of weeks and see what happens. Will also monitor how it goes once I get a couple more VM’s set up, running Server 2012 with Exchange and another running Server 2008 with SharePoint. That will add some heat to the situation and then see if Untangle can still keep up.

Will post again once I have a change to test the Integration Services and give an update on performance when we get into some more serious testing.

Update

Having now got this set up a bit more, and actually in a production environment, I have some more information on two things:

The Mouse

Now that it is in production, I am using a remote desktop connection to administer the Hyper-V host server. I can connect to the host server, and open up my Untanghle serve in the VM Connection – and the mouse does not work. If i plug back in a mouse to the actual server, I can use the mouse inside Untangle. So I guess if you are using a KVM solution to control your Hyper-V server then you will probably be ok, if not, you may be a touch stuck.

VLAN’s and Legacy Networking

The Internet connection is on a separate VLAN to the guest WIFI network, but the same switch. I wasn’t looking to put in any extra NIC’s to my Hyper-V host, so experimented with VLAN assignment.

I configured a NIC team (Broadcom adapters) on the Hyper-V host, with no VLAN assignments at that level, as per MS best practice. A Virtual Switch then connects to this, again with no VLAN assignment.

Of my two legacy NIC’s on the VM, one was configured for the public WIFI vlan, and one configured for the Internet VLAN. I rebooted the Untangle server and again this works. I was able to connect to the Untangle server from clients on the public wifi and be prompted with the desired capture portal page.

Interestingly, all of the NIC’s show as disconnected in Untangle, despite it working. I am guessing that must be an issue with how the VM is presenting NIC status to Linux.

Integration Services

As yet, I have not managed to get Integration Services installed.

Be the first to like.
Posted in Hyper-V, Internet Security, Server 2012 | 1 Comment

VBScript: Run an app that requires a Mapped Drive

Some software is just a pain. We encountered another program yesterday that requires a mapped drive to run off the network. You can’t use a UNC path as the hyperlinks don’t work properly to a number of linked documents. We don’t have mapped drives except for the users data and a single share. So we didn’t want another one persistent just for this program. Not going to name the application, but here is a workaround.

This simple script solves this problem. It does the following:

  1. Maps a drive to a specified location
  2. Checks that the drive has mapped correctly
  3. Runs the application from the mapped drive
  4. Monitors the current processes for the application to close
  5. Disconnects the mapped drive

All you need to do is edit the variables at the top to make it run for your application, and choose an appropriate drive letter. The command to run is purposely a different variable in case you need to run an application that is in the subfolder of the share.

Option Explicit
Dim objNetwork, intResult, objShell, intInstances, objWMIService, strWMIQuery, strDriveLettertoMap, strUNCPathtoMap, strApplicationName, strCommandtoRun
'Variables
strDriveLettertoMap = "O:"
strUNCPathtoMap = \\yourserver\yoursharename"
strApplicationName = "AppName.exe"
strCommandtoRun = "O:\SubFolder\AppName.exe"
'Map the network drive
Set objNetwork = WScript.CreateObject("WScript.Network")
intResult = objNetwork.MapNetworkDrive(strDriveLettertoMap , strUNCPathtoMap , False)
'Check that the drive mapped correctly. 
If intResult <> 0 Then
 Msgbox("There has been a problem starting the application. Please report this to your Network Administrator.")
 WScript.Quit
End If
'Start the Application
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run strCommandtoRun
Set objShell = Nothing
'Monitor the services and wait for the application to close. 
strWMIQuery = "Select * from Win32_Process where name like '" & strApplicationName & "'"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 
intInstances = 1
Do While intInstances > 0
    Wscript.Sleep 5000
    intInstances = objWMIService.ExecQuery(strWMIQuery).Count
Loop
'Remove the network drive
WScript.Sleep 2000
objNetwork.RemoveNetworkDrive strDriveLettertoMap

1 person found this post useful.
Posted in VBScript | Leave a comment

Sharepoint 2010: Unable to Display This Web Part. Error while executing web part: System.StackOverflowException: Operation caused a stack overflow.

I have got a live testing version of a SharePoint 2010 based room & reservations bookings template (which I promise I will one day finish!).

Randomly, users were getting an error on their screens though.

Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Microsoft SharePoint Foundation-compatible HTML editor such as Microsoft SharePoint Designer. If the problem persists, contact your Web server administrator.
Correlation ID:40dd096d-a486-44ed-8f27-af1d31530213.

The Correlation ID here, when looked up in the log files (c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS\) takes me to a 4 line description which starts:

Error while executing web part: System.StackOverflowException: Operation caused a stack overflow.

It turns out, that since the August 2011 Cumulative Update for SharePoint 2010, there is a timeout put on XSLT Transforms. My page in particular uses these transforms to draw the timeline of what rooms are available when. As far as I know this only affects DataViewWebParts.

In order to overcome this, after installing the February 2012 Cumulative Update for SharePoint 2010 you can configure this timeout period. This can be done by running the following commands at the SharePoint PowerShell prompt.

$myfarm = Get-SPFarm
$myfarm.XSLTTransformTimeout = 5
$myfarm.Update()

The page now appears correctly for everyone!

Note: The brackets at the end of the Update() line are essential. If you don’t put them in then the changes you make will not save. If you want to check that your change has been saved then enter the following two commands, and your new timeout will be shown.

$testfarm = Get-SPFarm
$testfarm.XSLTTransformTimeout

If you have particularly complex and involved XSLT then you may need to increase the timeout further. For the application that I was working on, 2 seconds worked for all users except for 1 time. We set it as 5 as a fail safe, as generally people will be happier with it working and waiting an extra second. If you go too high though, then you may be compromising the users experience, and should probably look at optimising your code, or creating a sub-class for the code as per the Microsoft KB: http://support.microsoft.com/kb/2639184

9 people found this post useful.
Posted in SharePoint | 7 Comments

Cannot Save Outlook Attachments when C:\ drive is Hidden

We have Outlook 2010, running on Windows 7 (both 64 bit). Our users were complaining that after opening an attachment in outlook, and going to save it, it came up with an error. Which was:

‘This operation has been cancelled due to restrictions in effect on this computer. Please contact your system administrator.’

To replicate the issue:

  1. Log on as a user who cannot see the C:\ drive in My Computer
  2. Send the user an email with a Word/Excel attachment
  3. Open the attachment
  4. Go to File –> Save As

The error will then appear.

A workaround to this, which stops the error appearing is to change a registry key. The key below sets where Outlook puts temporary attachments that you open.

HKEY_LOCAL_MACHINE\Software\Microsoft\Office\14.0\Outlook\Security\OutlookSecureTempFolder

In our case we changed the value of this setting to a folder within their My Documents called Microsoft Outlook Temporary Attachments (so the path became U:\My Documents\Microsoft Outlook Temporary Attachments). Restart Outlook and repeat the above steps and the error should disappear.

Not yet created a script or GPO to do this, but if I do then I will post an update.

Be the first to like.
Posted in Office 2010 | Leave a comment

Get AD Group Members in Text File

Just a quick post – I needed to dump all the members of all groups in an OU to a text file in a sort-of pretty way. The result? See below.

This short script asks the user for an LDAP path to an OU which contains groups. The script then searches that OU for all the groups, and dumps a list of all the users’ samAccountName and DisplayName into a text file, along with a count up of all the group members. For this script I just dumped it all to a file with the default file name of GroupMembers. Possibly a base for adaption this one – but might help someone.

'Gets all the members of all the groups in the specified OU.
'Outputs to a text file in the current folder.
'Craig Tolley
'3rd April 2012
'-----------------------------------------------------------
Option Explicit
'Declare all variables.
Dim objGroup, objMember, objOU, objGrp, strLDAPPath, objFSO, objOutput
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutput = objFSO.OpenTextFile("GroupsOutput.txt",8,True)
'Get the LDAP Path to find groups in
strLDAPPath = ""
Do While strLDAPPath = ""
 strLDAPPath = InputBox("Type the path of the OU which contains the groups you want information on. e.g ""LDAP://OU=Groups,OU=Company,DC=domain,DC=local""")
Loop
objOutput.WriteLine("OU to Search: " & strLDAPPath)
objOutput.WriteLine("-----------------------------------------------------------")
objOutput.WriteLine("")
'Find the Groups in AD
Set objOU = GetObject(strLDAPPath)
objOU.Filter = Array("group")
'Cycle through the groups.
For Each objGroup in objOU
 objOutput.WriteLine("Group Name: '" & objGroup.samAccountName & "'")
 For Each objMember In objGroup.Members
  objOutput.WriteLine(" " & objMember.sAMAccountName & " - " & objMember.DisplayName)
 Next
 objOutput.WriteLine( "Total Group Members: " & objGroup.Members.Count)
 objOutput.WriteLine("-----------------------------------------------------------")
 objOutput.WriteLine("")
Next
Msgbox("Completed Output of Groups")

2 people found this post useful.
Posted in Active Directory, VBScript | 2 Comments

VBA: Create Slide for every Picture in a Folder

This short script runs in PowerPoint VBA. It looks in a given folder for any image and creates a new slide for that image. Once the image has been inserted it determines if the image is portrait or landscape and then resizes the picture, keeping the proportions, to fit the given slide layout as best it can.  

Option Explicit
Sub CreatePictureSlidesByFolder()
   'Define Variables
    Dim PictureFolder As String
    Dim CurrentSlide As Slide
    Dim CurrentFile As String
    Dim CurrentFileFullName As String
    Dim AllowedExtensions() As Variant
    
    'Set the Path to the folder of pictures
    PictureFolder = "\\data\staffdata\ctolley\My Pictures\Sample Pictures"
    
    'Check that the Picture folder path has a trailing \
    If Right(PictureFolder, 1) <> "\" Then PictureFolder = PictureFolder & "\"
    
    'Define the allowed picture extensions
    AllowedExtensions = Array("jpg", "png", "bmp")
    
    'Check that 1 slide exists in the presentation
    If ActivePresentation.Slides.Count = 0 Then
        ActivePresentation.Slides.Add 1, ppLayoutTitle
        ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text = PictureFolder
    End If
    
    'Get the files in the folder
    CurrentFile = Dir(PictureFolder)
    
    While CurrentFile <> ""
    
    'Check that the file extension is allowed
    If IsStringInArray(GetFileExtension(CurrentFile), AllowedExtensions) Then
    
        'Make the full file name
        CurrentFileFullName = PictureFolder & CurrentFile
    
        'Add a new slide to the presentation
        Set CurrentSlide = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
        
        'Add the picture to the presentation
        With CurrentSlide.Shapes.AddPicture(CurrentFileFullName, msoFalse, msoTrue, 0, 0)
        
            'Check if the picture is landscape or portrait
            
            If .Width > .Height Then
                'Landscape
                .Width = ActivePresentation.PageSetup.SlideWidth
                .Left = 0
                .Top = (ActivePresentation.PageSetup.SlideHeight - .Height) / 2
            
            Else
                'Portrait
                .Height = ActivePresentation.PageSetup.SlideHeight
                .Left = (ActivePresentation.PageSetup.SlideWidth - .Width) / 2
                .Top = 0
            End If
            
        End With
        
    End If
            
    'Clear the current file
    CurrentFile = Dir
    
    Wend
End Sub

Public Function GetFileExtension(TheFilePath As String) As String
    'Separates the file extension from the file name and returns it.
    Dim FileParts() As String
    FileParts = Split(TheFilePath, ".")
    GetFileExtension = FileParts(UBound(FileParts))
End Function
Public Function IsStringInArray(TheString As String, TheArray() As Variant) As Boolean
    'Determines if the passed string is in the passed array.
    Dim ArrIdx As Integer
    For ArrIdx = LBound(TheArray) To UBound(TheArray)
        If TheString Like TheArray(ArrIdx) Then IsStringInArray = True
    Next ArrIdx
End Function

4 people found this post useful.
Posted in Microsoft Office | Leave a comment

Resizing a Dynamic System Partition on Windows 2003 – for Free.

Ok. I have a server running Windows Small Business Server 2003. Back in the day when it was set up I naively had only a 20gb System volume, on a dynamic disk, mirrored. Unfortunately that ran out of space, so I set about extending the partition.

Windows Disk Management and Diskpart in Windows 2003 don’t allow you to extend the volume with the O/S on it. This limitation meant that I went to a tried, tested and trusted friend in GParted. Unfortunately, GParted also cannot extend volumes on dynamic disks created with the Windows LVM.

After an hour of trying to find a way to do it, I nearly ended up paying for professional tools (which do exist if you want the support and backup). I then remembered that Windows 2008 does allow you to resize the system partition.

This means that the Windows 2008 version of DiskPart can perform this function, and is included in Windows PE 3.

So, grab a copy of the Windows Automated Installation Kit from here: http://www.microsoft.com/download/en/details.aspx?id=5753 create your Windows PE 3.0 CD and boot. Instructions for creating the CD or UFD are here: http://technet.microsoft.com/en-us/library/cc749311(WS.10).aspx

Full instructions for the Windows 2008 version of DiskPart can be found here: http://technet.microsoft.com/en-us/library/cc770877(WS.10).aspx

Remember to always create a backup though.

5 people found this post useful.
Posted in Server 2003 | Leave a comment

Data Protection – Just Can’t Get Enough

Ok, not strictly IT here, but important none the less.

Data Protection is big, and whilst you personally cannot be prosecuted for breaching the Act, your company can be fined.

Just had a check up on the Information Commissioners Office (ICO) – and found some new resources.

Th!nk Privacy is a campaign developed between the ICO and Blue Goose. It is a collectionof posters and resources which can be used to reinforce your Data Protection training. Use it on routine security sweeps and compliance should increase.

Combine this with the ICO’s offering of free resources for organisations which they can use to protect themselves and provide training.

All this provides you with no reason to protect personal information and comply with the Data Protection Act. The weakest link tends to be staff, so use this to reduce that risk.

Th!nk Privacy: http://www.ico.gov.uk/news/current_topics/think_privacy.aspx

ICO Publications: https://www.ico.gov.uk/tools_and_resources/request_publications.aspx

3 people found this post useful.
Posted in General Stuff | Leave a comment

Disable ‘Automatically detect settings’ in Internet Explorer

This script allows you to turn off (or on) the ‘Automatically Detect Settings’ check box in Internet Explorer.

I have not been able to find a way which guarantees that this will not be checked. You can set a Group Policy into Internet Explorer Preference Mode, but if a user later changes it, then it will not change back. If you Disable Changing IE Proxy Settings, then the Preference Mode Setting seems not to work.

I have set this script to run at logon, as part of our general login script. It only modifies that one setting, no others. It reads the entire of the binary value, modifies the one binary value that needs changing and then writes back the entire value.

Option Explicit
On Error Resume Next
'Create a constant for the HKEY_CURRENT_USER object
Const HKCU = &H80000001
'Define variables
Dim strComputer
Dim strRegistryKey
Dim objRegistry
Dim strRegistryValue
DIm binValue
strComputer = "."
strRegistryKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
strRegistryValue = "DefaultConnectionSettings"
'Connect to the Registry
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
'Retrieve the current settings. 
objRegistry.GetBinaryValue HKCU, strRegistryKey, strRegistryValue, binValue
'Change the 'Automatically detect settings' box to unticked
binValue(8) = 05
'binValue(8) = 13 - Enable this line to check the box instead of uncheck
'Save the changes
objRegistry.SetBinaryValue HKCU, strRegistryKey, strRegistryValue, binValue

9 people found this post useful.
Posted in Internet Security, VBScript | 6 Comments
  • Tags

  • Categories

  • May 2013
    M T W T F S S
    « Jan    
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
  • Meta

  • Top Liked Posts

    Powered by WP Likes

Swedish Greys - a WordPress theme from Nordic Themepark.