Processing NULL AD values

Back in this post https://richardspowershellblog.wordpress.com/2012/12/09/bulk-modifications-using-set-aduser/

I showed how to perform a bulk change to a number of AD accounts using a CSV file to input the data

I was recently asked what happens if one of the input values is null.

£> Set-ADUser -Identity fgreen  -Division ‘Test’
£> Get-ADUser -Identity fgreen  -Properties Division

DistinguishedName : CN=Fred Green,OU=Testing,DC=Manticore,DC=org
Division          : Test
Enabled           : False
GivenName         : Fred
Name              : Fred Green
ObjectClass       : user
ObjectGUID        : 8cf64233-9a87-43dc-8ce1-4f26bf78e12d
SamAccountName    : fgreen
SID               : S-1-5-21-195014076-723736408-1406369008-1112
Surname           : Green
UserPrincipalName : fgreen@Manticore.org

 

£> $div = $null
£> Set-ADUser -Identity fgreen  -Division $div
£> Get-ADUser -Identity fgreen  -Properties Division

DistinguishedName : CN=Fred Green,OU=Testing,DC=Manticore,DC=org
Division          :
Enabled           : False
GivenName         : Fred
Name              : Fred Green
ObjectClass       : user
ObjectGUID        : 8cf64233-9a87-43dc-8ce1-4f26bf78e12d
SamAccountName    : fgreen
SID               : S-1-5-21-195014076-723736408-1406369008-1112
Surname           : Green
UserPrincipalName : fgreen@Manticore.org

 

If the value is already set – a NULL value will effectively clear it

 

If a value isn’t set – nothing happens

£> $div = $null
£> Get-ADUser -Identity dbrown  -Properties Division

DistinguishedName : CN=Dave Brown,OU=Testing,DC=Manticore,DC=org
Division          :
Enabled           : False
GivenName         : Dave
Name              : Dave Brown
ObjectClass       : user
ObjectGUID        : 346649f7-6f69-4f20-985f-b2b08674b942
SamAccountName    : dbrown
SID               : S-1-5-21-195014076-723736408-1406369008-1109
Surname           : Brown
UserPrincipalName : dbrown@Manticore.org

 

£> Set-ADUser -Identity dbrown  -Division $div
£> Get-ADUser -Identity dbrown  -Properties Division

DistinguishedName : CN=Dave Brown,OU=Testing,DC=Manticore,DC=org
Division          :
Enabled           : False
GivenName         : Dave
Name              : Dave Brown
ObjectClass       : user
ObjectGUID        : 346649f7-6f69-4f20-985f-b2b08674b942
SamAccountName    : dbrown
SID               : S-1-5-21-195014076-723736408-1406369008-1109
Surname           : Brown
UserPrincipalName : dbrown@Manticore.org

 

An empty string on the otherhand

$div = ”
Set-ADUser -Identity dbrown  -Division $div

 

Set-ADUser : replace
At line:1 char:1
+ Set-ADUser -Identity dbrown  -Division $div
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (dbrown:ADUser) [Set-ADUser], ADInvalidOperationException
    + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.SetADUser

 

Causes an error

 

Bottom line – if you’re passing in a CSV file check that the values in it aren’t NUL or empty – either by validating the parameters in your function or by writing extra code. The first way is much preferred

SharePoint Pitfalls: Creating a Visual Studio Project Without SharePoint Locally Installed

This is the first on a (huge) collection of posts on SharePoint pitfalls. Hope you enjoy, and, please, do send me your feedback!

If you do not have SharePoint locally installed, Visual Studio will not let you create a SharePoint project:

sp-not-installed

Fortunately, it is easy to go around this in two simple steps:

  1. Registry

    In the Registry, add the following key: HKEY_LOCAL_MACHINESOFTWAREMicrosoftShared ToolsWeb Server Extensions15.0SharePoint

    In it, add two string values: Location=C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15 and SharePoint=Installed

  2. Global Assembly Cache

    Copy the following assemblies from a machine where SharePoint is installed (C:WindowsMicrosoft.NETGAC_32) into your development machine and add them to the GAC (gacutil):

    • Microsoft.SharePoint.dll
    • Microsoft.SharePoint.Client.dll
    • Microsoft.SharePoint.Client.Publishing.dll
    • Microsoft.SharePoint.Client.Runtime.dll
    • Microsoft.SharePoint.Client.ServerRuntime.dll
    • Microsoft.SharePoint.Library.dll
    • Microsoft.SharePoint.Linq.dll
    • Microsoft.SharePoint.Portal.dll
    • Microsoft.SharePoint.Publishing.dll

    Of course, you may need others as well.

Enjoy!

How to Change what New Tabs in Microsoft Edge Open with in Windows 10

Microsoft has announced the new name for its next-generation web browser in Windows 10. Ditching the Project Spartan development codename, the browser will now be known as Microsoft Edge.

Microsoft Edge is a new web browser added in Windows 10, and will be available across the Windows 10 device family. It is fast, compatible, and built for the modern Web.

When you open a new tab by clicking or tapping on the New tab button or by pressing the Ctrl+T keys in Microsoft Edge, the new tab opens with top sites by default.

This tutorial will show you how to open new tabs with top sites and suggested content, top sites, or a blank page in Microsoft Edge for your account in Windows 10.

Read more…

My First MSDN Magazine Article: Using STL Strings at Win32 API Boundaries

My first article for MSDN Magazine is online! I’m excited about that. Crafting that article has been an interesting, fun and rewarding experience.

Using STL Strings at Win32 API Boundaries

I still recall when I was 20 years young, and used to visit a local newsstand looking forward to buy MSJ (Microsoft Systems Journal), later merged into MSDN Magazine, and delving into it.

I’d like to express my sincere gratitude to Stephan T. Lavavej for his thorough review, to my editor Sharon Terdeman for handling my article in a great way and for her excellent communication, and to Eric Battalio, Gordon Hogenson and MSDN Magazine editor-in-chief Michael Desmond for the initial contacts and for starting the process.

I hope you enjoy reading the article.

String startswith method

If you look at the methods available on a string one of them is StartsWith(). It tests if a given string starts with another string

 

£> ‘frgrughrugu’.StartsWith

OverloadDefinitions
——————-
bool StartsWith(string value)
bool StartsWith(string value, System.StringComparison comparisonType)
bool StartsWith(string value, bool ignoreCase, cultureinfo culture)

 

 

The first option is the easiest to use and the most common scenario

 

£> ‘frgrughrugu’.StartsWith(‘frg’)
True
£> ‘frgrughrugu’.StartsWith(‘xya’)
False

 

Unlike most things in PowerShell this comparison is NOT case insensitive

£> ‘frgrughrugu’.StartsWith(‘fRg’)
False

 

The second option helps by letting you use the members of the System.StringComparison enumeration to control the way the comparison is performed

 

£> $ct = [System.StringComparison]::CurrentCultureIgnoreCase

 

£> ‘frgrughrugu’.StartsWith(‘frg’, $ct)
True
£> ‘frgrughrugu’.StartsWith(‘fRg’, $ct)
True

 

The final option allows you to use a culture to control the way the comparison is performed. $null implies use the current culture. Note how the boolean controlling the case sensitivity works:

£> ‘frgrughrugu’.StartsWith(‘frg’, $true, $null)
True
£> ‘frgrughrugu’.StartsWith(‘fRg’, $true, $null)
True
£> ‘frgrughrugu’.StartsWith(‘fRg’, $false, $null)
False
£> ‘frgrughrugu’.StartsWith(‘frg’, $false, $null)
True

Spybot Search & Destroy Weekly Update – July 1, 2015

2015-07-01

Adware
++ Ad.Jollywallet ++ Ad.PlurPush + InstallMonetizer ++ Rubar.Toolbar + Win32.Kradda.dm + Yontoo.Pagerage
PUPS
++ Conduit.QiSu ++ PU.ASC.FinallyFast ++ PU.ASC.PerformanceCenter
Trojan
+ Win32.Downloader.HicrazykA ++ Win32.Tracur
Total: 2608585 fingerprints in 819453 rules for 7485 products.

http://www.safer-networking.org/about/updates/

Removal instructions for CPlus.3cV27.06

What is CPlus.3cV27.06?

The Malwarebytes research team has determined that CPlus.3cV27.06 is a browser hijacker. These so-called “hijackers” manipulate your browser(s), for example to change your startpage or searchscopes, so that the affected browser visits their site or one of their choice. This one also displays advertisements.

https://forums.malwarebytes.org/index.php?%2Ftopic%2F169998-removal-instructions-for-cplus3cv2706%2F

Domain Admins password last set

A recent question on the forums asked about getting the date a password was last set and the password never expires status for the domain admins group

This is one way of doing it

 

Get-ADGroupMember -Identity ‘Domain Admins’ |
foreach {
Get-ADUser -Identity $psitem.samAccountName -Properties PasswordLastSet, PasswordNeverExpires |
select Name, PasswordLastSet, PasswordNeverExpires
}

 

Get the group and for each member get the aduser information and select the properties to display.

 

Get-ADGroupMember and Get-AdUser work together on the pipeline so you can also do this:

 

Get-ADGroupMember -Identity ‘Domain Admins’ |
Get-ADUser -Properties PasswordLastSet, PasswordNeverExpires |
select Name, PasswordLastSet, PasswordNeverExpires

LEAP SECOND 2015 – 2000 Networks impacted and quickly recovered

This link in Network World documents impacts caused by adding an additional second to the day and systems using the Network Time Protocol going out sync.  However, this year more advanced preparation kept vast majority of networks running smoothly throughout the transition.

http://www.networkworld.com/article/2942994/leap-second-causes-internet-hiccup-particularly-in-brazil.html

The addition of a leap second to world clocks on Wednesday caused some networks to crash although most quickly recovered.  Some 2,000 networks stopped working just after midnight Coordinated Universal Time (UTC), said Doug Madory, director of Internet analysis with Dyn, a company studies global Internet traffic flows.

Nearly 50 percent of those networks were in Brazil, which may indicate that ISPs use a common type of router that may not have been prepared for the leap second, he said.  Most of the networks quickly recovered, which may have required just a reboot of a router, Madory said.

The Internet’s global routing table, a distributed database of networks and how they connect, contains more than 500,000 networks, so the problems affected less than a half a percent, Madory said. The last leap second, added in 2012, caused problems for Linux systems such as slowdowns or CPU freezes. This time around, however, many companies looked to avoid issues with better preparation.

Becas Microsoft DPE 2015-2016

Ha llegado el verano y como ya empieza a ser una tradición, también el proceso de selección de las becas técnicas de DPE en Microsoft España.

Para los que no conocéis DPE, es el departamento de Microsoft que se encarga de transmitir pasión por la tecnología. Trabajamos para que estudiantes técnicos, programadores y administradores de sistemas de toda España conozcan las últimas novedades en programación, devops, cloud, bigdata, IoT… y puedan sacarle el máximo provecho a través de la plataforma y herramientas de Microsoft.

Para conseguirlo participamos en todo tipo de comunidades técnicas, organizamos eventos, webcasts, publicamos tutoriales, programamos pruebas de concepto y ayudamos a solucionar las dudas técnicas que puedan surgir.

 

http://blogs.msdn.com/b/esmsdn/archive/2015/06/30/becas-microsoft-dpe-2015-2016.aspx

 

Windows 10 – New LOGIN screen introduced in build 10159

Microsoft continues to add a few more innovations and special features for the forthcoming “GOLD” copy that will debut on July 29th

http://www.pcworld.com/article/2942892/microsoft-releases-its-second-windows-10-build-in-two-days.html

Microsoft surprised testers of Windows 10 on Tuesday by launching build 10159 of its forthcoming operating system, just a day after the last update. Gabe Aul, an engineering general manager at Microsoft who serves as the public face of the Windows Insider Program, announced in a blog post that the company released the new build to testers in the program’s Fast ring.

Unlike yesterday’s build 10158, the latest build doesn’t bring that many new features. Instead, wrote Aul, it’s packed with more than 300 bug fixes, along with a mysterious “very interesting change.”  According to a report by Neowin, the change in question is a redesign of the login screen that puts a user’s photo front and center in a translucent pane over their desktop picture. It’s a marked difference from the previous iteration of the login screen, which placed a user’s photo to one side of their name, Microsoft account email and password field.

LEAP SECOND 2015 – Technical impacts of adjusting time on JUNE 30, 2015

Companies around the world used innovative & interesting solutions to work around timing differences associated with adding an extra second to the official atomic clock.

http://www.channelnewsasia.com/news/singapore/leap-second-clocks-to/1952442.html

Leap second: Clocks to read 07:59:60 on Wednesday

The phenomenon, which is implemented every few years, prevents days from getting longer as the Earth’s rotation continually slows down due to factors such as the moon’s gravitational pull and earthquakes. The phenomenon, called a “leap second”, takes place every few years, where an additional second is inserted to the atomic clock, or UTC (Coordinated Universal Time).

During the last leap second on Jun 30, 2012, more than 400 Qantas flights were delayed when the airline’s check-in system crashed, while websites such as Reddit, Mozilla and LinkedIn experienced glitches because the systems could not cope with the extra time.  This year, the leap second insertion is especially crucial to Asia as it takes place during working hours, unlike the early Sunday morning three years ago.

“In the past, leap seconds happened during weekends (and) holidays, so people were not working. … This year, (the leap second) is expected to affect more financial sectors because it’s during (trading) time,” said Dr Liu Yan Ying, a metrologist at the National Metrology Centre of the Agency for Science, Technology and Research (A*STAR). The centre oversees the national measurement standards in Singapore.

Removal instructions for Great Find

What is Great Find?

The Malwarebytes research team has determined that Great Find is a browser hijacker. These so-called “hijackers” manipulate your browser(s), for example to change your startpage or searchscopes, so that the affected browser visits their site or one of their choice. This one also displays advertisements.

https://forums.malwarebytes.org/index.php?/topic/169923-removal-instructions-for-great-find/

Removal instructions for WikiBrowser

What is WikiBrowser?

The Malwarebytes research team has determined that WikiBrowser is a browser hijacker. These so-called “hijackers” manipulate your browser(s), for example to change your startpage or searchscopes, so that the affected browser visits their site or one of their choice. This one hijacks the shortcuts to your other browsers.

https://forums.malwarebytes.org/index.php?/topic/169879-removal-instructions-for-wikibrowser/

How to Manage Optional Features in Windows 10

This tutorial will show you how to add or remove optional features for all users in Windows 10.

Read more…

Removing HomeDrive and HomeFolder settings

 

Back in this post https://richardspowershellblog.wordpress.com/wp-admin/post.php?post=2343&action=edit I showed how to set the users home directory and home drive.

 

I was recently asked how to remove entries from those attributes.

 

The easiest way is to use the –Clear parameter with set-AdUser

 

Set-ADUser -Identity gdreen -Clear HomeDrive, HomeDirectory

How to Add or Remove Home Button in Microsoft Edge in Windows 10

Microsoft has announced the new name for its next-generation web browser in Windows 10. Ditching the Project Spartan development codename, the browser will now be known as Microsoft Edge.

Microsoft Edge is a new web browser added in Windows 10, and will be available across the Windows 10 device family. It is fast, compatible, and built for the modern Web.

Microsoft Edge includes a home button that you can add or remove from the toolbar. When you click/tap on the home button, it will take you the site you specify when turned on.

This tutorial will show you how to add or remove a home button that opens a home page you set in Microsoft Edge for your account in Windows 10.

Read more…

CIM filters

I was looking up Win32_SystemDriver on the MSDN site and noticed there was some PowerShell example code

 

Get-WmiObject -Class Win32_SystemDriver |
Where-Object -FilterScript {$_.State -eq "Running"} |
Where-Object -FilterScript {$_.StartMode -eq "Manual"} |
Format-Table -Property Name,DisplayName

 

A better way to write this would be:

Get-WmiObject -Class Win32_SystemDriver -Filter "State=’Running’ AND StartMode=’Manual’" | Format-Table -Property Name, DisplayName –AutoSize

 

or

 

Get-CimInstance -ClassName Win32_SystemDriver -Filter "State=’Running’ AND StartMode=’Manual’" | Format-Table -Property Name, DisplayName -AutoSize

 

Do the filtering in the CIM call – especially if you’re running this against a number of remote machines. That way you limit the network traffic you’re returning

Facebook – Improved Mobile photo editor in development

Facebook will be improving photo upload capabilities in the coming months as documented in article below

http://www.pcmag.com/article2/0,2817,2486942,00.asp

Facebook is about to make it a lot easier for users to spruce up their photos before posting them to the social network. According to TechCrunch, Zuckerberg and Co. appear to be testing a new Snapchat-like photo uploader for the Facebook iOS app, which will let you jazz up your photos with text, filters, and stickers.

Facebook iOS photo edit toolsJust select a photo like you normally would and you’ll see a vertical line swipe across the image. From here, you can swipe right to select a different filter. At this point, Facebook’s selection of filters is small. There’s Auto, which will just correct the color; Vintage for a sepia look; Spring to brighten it up; Summer to give your image a golden tone; Fall for a more orangey look; Winter for a more muted, moody look; and Snow for black and white.

Parsing ipconfig /displaydns with regular expressions

In yesterdays post I used a series of split operations to parse the strings produced by ipconfig /displaydns

 

Regular expressions should give a more power full way to perform this task. Not being a big fan of regular expressions I tend not to use them but for the sake of experimentation I thought I’d try and figure out a set of regex to use.

 

This is as far as I’ve got

 

$props = [ordered]@{
  RecordName = ""
  RecordType = ""
  Section    = ""
  TimeToLive = 0
  DataLength = 0
  Data       = ""
}

$recs = @()

$cache = ipconfig /displaydns
for($i=0; $i -le ($cache.Count -1); $i++) {
if ($cache[$i] -like ‘*Record Name*’){
    $rec = New-Object -TypeName psobject -Property $props
    $rec.RecordName = $cache[$i] -replace "(s*w*){2}(s.){5}(s:s)", ""
    $rec.Section = $cache[$i+4] -replace "s*w*(s.){7}(s:s)", ""
    $rec.TimeToLive = $cache[$i+2] -replace "(s*w*){3}s(s.){4}(s:s)", ""
    $rec.DataLength = $cache[$i+3] -replace "(s*w*){2}(s.){5}(s:s)", ""
   
    $irec = ($cache[$i+5] -split ": ")
    $rec.RecordType = ($irec[0].TrimStart() -split ‘ ‘)[0]
    $rec.Data = $irec[1]

    $recs += $rec
}
else {
    continue
}
}

$recs | Format-Table –AutoSize

 

I still need to work out how to process the data and record type using regular expressions

Recent Comments

Archives