Set Active Directory HomeDirectory with Powershell

Need to update the HomeDirectory on a bulk set of users, based on OU? See below. It will set \\SERVERNAME\Username as the home directory. Change the OU path as needed.

Get-ADUser -Filter * -SearchBase 'ou=YourOU,ou=Users,dc=DOMAIN,dc=LOCAL' | ForEach-Object {
	Set-ADUser $_.SamAccountName -HomeDrive "H:" -HomeDirectory "\\SERVERNAME\$($_.SamAccountName)"
}
Posted in Powershell | Tagged | Leave a comment

Change Default Gateway with a Batch file

Below is a useful script to change a default gateway IP address on a Windows 7 network adapter.

@ECHO OFF
Set Gateway=192.168.1.99
for /f "tokens=4*" %%a in ('netsh interface ipv4 show interfaces ^| find " connected" ^| find /v /i "Loopback"') do Set NIC=%%b
netsh interface ipv4 delete route prefix=0.0.0.0/0 interface="%nic%"
netsh interface ipv4 add route prefix=0.0.0.0/0 interface="%nic%" nexthop=%gateway% publish=Yes
Posted in Windows | Tagged , , | Leave a comment

The application was unable to load a required virtual machine component. Please contact the publisher of this application for more information.

Windows Updates have lately broken some software and thrown the error message “The application was unable to load a required virtual machine component. Please contact the publisher of this application for more information.”

I have put together a batch file to remove all the updates from a Windows 7 system that causes this issue.

@echo off

echo Uninstalling 3022345
wusa.exe /uninstall /kb:3022345 /quiet /norestart

echo Uninstalling 3045999
wusa.exe /uninstall /kb:3045999 /quiet /norestart

echo Uninstalling 3068708
wusa.exe /uninstall /kb:3068708 /quiet /norestart

echo Uninstalling 3071756
wusa.exe /uninstall /kb:3071756 /quiet /norestart

echo Uninstalling 3046017
wusa.exe /uninstall /kb:3046017 /quiet /norestart

echo Uninstalling 3060716
wusa.exe /uninstall /kb:3060716 /quiet /norestart

echo Uninstalling 3080149
wusa.exe /uninstall /kb:3080149 /quiet /norestart

echo Uninstalling 3101746
wusa.exe /uninstall /kb:3101746 /quiet /norestart

echo Uninstalling 3121212
wusa.exe /uninstall /kb:3121212 /quiet /norestart

echo Uninstalling 3088195
wusa.exe /uninstall /kb:3088195 /quiet /norestart

echo Uninstalling 3093513 with Restart
wusa.exe /uninstall /kb:3093513 /quiet
echo Forcing Restart...
END

Save as a .bat file and run. It will get the to end update and force a restart of the machine.

Posted in Tutorials | Tagged , , , | Leave a comment

Useful SCCM 2012 Device Collection Queries

Below are some useful SCCM Device Collection Queries. Some of these may require the device collection to be Dynamic.

Device Collection based on OU

SELECT * from SMS_R_System WHERE SMS_R_System.SystemOUName = "YOURDOM.LOCAL/Computers/YourCustomOU"

Device Collection Laptops/Notebooks

SELECT * FROM SMS_R_System INNER JOIN SMS_G_System_SYSTEM_ENCLOSURE ON SMS_G_System_SYSTEM_ENCLOSURE.ResourceID = SMS_R_System.ResourceID WHERE SMS_G_System_SYSTEM_ENCLOSURE.ChassisTypes in ( "8", "9", "10", "14" ) 

64bit Devices

SELECT * FROM SMS_R_System INNER JOIN SMS_G_System_COMPUTER_SYSTEM ON SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceID WHERE SMS_G_System_COMPUTER_SYSTEM.SystemType = "x64-based PC" 

Windows 8 Devices

SELECT SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client
FROM SMS_R_System
INNER JOIN
SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId
WHERE
SMS_R_System.OperatingSystemNameandVersion
LIKE
"%Workstation 6.2%" or SMS_R_System.OperatingSystemNameandVersion LIKE "%Windows 8%" 

All Servers

SELECT SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client FROM SMS_R_System INNER JOIN SMS_G_System_SYSTEM ON SMS_G_System_SYSTEM.ResourceId = SMS_R_System.ResourceId WHERE SMS_G_System_SYSTEM.SystemRole = "Server"

Domain Controllers

SELECT SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client FROM SMS_R_System WHERE SMS_R_System.PrimaryGroupID = "516"

Computer Name Contains…

SELECT SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client FROM SMS_R_System INNER JOIN SMS_G_System_SYSTEM ON SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId WHERE SMS_G_System_SYSTEM.Name LINK "%COMP%" ORDER BY SMS_R_System.Name
Posted in Blog, Techy | Tagged , , , , | Leave a comment

Quick Full-Disk Backups with Disk2VHD

Microsoft Sysinternals have free utility available to make full VHD backups from your hard drive. Using a VHD backup you can mount it in Windows and also import it into virtualisation software such as VirtualBox or VMWare and Hyper-V.

You can download the software from here:http://technet.microsoft.com/en-gb/sysinternals/ee656415.aspx

Below is a simple batch script to create automated backups using the command line; which can be set on a schedule.

Save the following as VHD.bat. Edit the backup_path variable with the location to store the backup. By default DISK2VHD will select all drives on the machine.

@ECHO OFF
ECHO Starting DISK2VHD Backup
SET starttime=%time%
SET backup_path=\\share\backups\
ECHO Backup started at: %starttime% > log.txt
IF NOT EXIST %backup_path%\%computername% MKDIR %backup_path%\%computername%
disk2vhd.exe * %backup_path%\%computername%\%computername%.vhd -accepteula
SET endtime=%time%
ECHO.
ECHO Backup completed at: %endtime% > log.txt
PAUSE
Posted in Programming | Tagged , , , | Leave a comment

VBScript – Check User is a member of AD Group

Just a quick snippet of VBScript – To check whether or not the current user is a member of a specific Active Directory group. This could be useful when deploying scripts via GPO or using it in a netlogon script.

The example below checks to see if the user belongs to “Domain Admins” – Replace this with whatever group you would like to check.

Option Explicit
Dim objShell,grouplistD,ADSPath,userPath,listGroup
On Error Resume Next
set objShell = WScript.CreateObject( "WScript.Shell" )
  
If isMember("Domain Admins") Then
       MsgBox("Is member")
End If
  
Function IsMember(groupName)
    If IsEmpty(groupListD) then
        Set groupListD = CreateObject("Scripting.Dictionary")
        groupListD.CompareMode = 1
        ADSPath = EnvString("userdomain") & "/" & EnvString("username")
        Set userPath = GetObject("WinNT://" & ADSPath & ",user")
        For Each listGroup in userPath.Groups
            groupListD.Add listGroup.Name, "-"
        Next
    End if
    IsMember = CBool(groupListD.Exists(groupName))
End Function
  
Function EnvString(variable)
    variable = "%" & variable & "%"
    EnvString = objShell.ExpandEnvironmentStrings(variable)
End Function

Set objShell = Nothing
Posted in Programming, VBScript | Tagged , , , , | Leave a comment

Powershell – List and Assign Office 365 Licenses

Microsoft are adding more and more functionality for administrators in Office 365 – Unfortunately, there is still no ‘easy’ and quick way to assign a new license, in bulk, to a lot of existing users. Specifically, the OFFICESUBSCRIPTION_STUDENT that was introduced to provide Office 365 licenses to Students was the one I was looking for.

Below are some quick Powershell commands to get you started (assuming that you know how to connect to Office 365 Exchange Online via Powershell)

List SKUs / Licenses Available
This will list your organisation before the SKU name, e.g. YOUR_ORG:OFFICESUBSCRIPTION_STUDENT

Get-MsolAccountSku

Add Single License to User
You can pipe this | with Get-MsolUser to set the license on a single user.

Set-MsolUserLicense -AddLicenses YOUR_ORG:OFFICESUBSCRIPTION_STUDENT

Bulk Add by Domain Name
If you have multiple domains, or sub-domains you can assign licenses in bulk easily. Replace the ‘your org’ strings below to match your setup though.

Get-MsolUser -DomainName staff.yourorg.com -All | Set-MsolUserLicense -AddLicenses YOUR_ORG:OFFICESUBSCRIPTION_STUDENT

You can use multiple filters on the last command and just pipe the second command using the |. This could be by name, by group or domain as show above.

Posted in Powershell | Tagged , , | Leave a comment

HVBackup – FREE Hyper-V Backup Solution (Modifications)

There is a free Microsoft Hyper-V backup solution called HVBackup – Website Link ; this is open-sourced under the LGPL license and is free to download and modify to suit your needs.

You can download and use this on your Hyper-V servers now by using the link above. I have been making changes to the HVBackup source to add a few new features, mainly…

  • Added GZIP Support (added by Pablo, on the HVBackup Forums)
  • Added GZIP Password (added by Pablo, on the HVBackup Forums)
  • HVBackup no longer responds to Command Line parameters, instead it reads all information from Settings.ini located in the same folder.
  • A GUI has been created to configure the settings, add servers, change formats, zip type, compression etc.
  • A Scheduler has been added to the GUI which allows you to Schedule HVBackup’s via the Windows Task Scheduler.

The new GUI I’ve written has been made in VB.NET and it manipulates the .ini settings file, allowing you to query your Hyper-V instance for server names and providing a quick interface for creating scheduling options via the Windows Task Scheduler.

This will be available for download shortly, if anyone wants to try this out feel free to contact me and I’ll send it over.

A couple of screenshots of the new GUI are below:

HBC2     HBC1

 

Posted in Programming | Tagged , , , , , | Leave a comment