Conference–time to book

Registration is open for the PowerShell Summit (USA) and PowerShell Conference (Europe). Now is an excellent time to decide which one you’re going to attend next year. If you’re serious about PowerSHell you should be at one of these events.

PowerShell Summit – https://eventloom.com/event/home/summit2017

PowerShell Conference – http://www.psconf.eu/

Posted in Powershell | Leave a comment

PowerShell finally the de facto shell

After 10 years PowerShell has become the de facto shell for Windows!

Windows Insider Preview build 14971 released yesterday uses PowerShell instead of cmd.exe as the default shell in Start Menu or File Explorer.

See https://blogs.windows.com/windowsexperience/2016/11/17/announcing-windows-10-insider-preview-build-14971-for-pc/#66Smq5KicvsTBzld.97

for this and other new features

Posted in Powershell, Windows 10 | Leave a comment

Changing the samAccountName

I was recently asked how the samAccountName – also referred to as the login id – could be changed.

First lets look at an account:

PS C:\Scripts> Get-ADUser -Identity 'FredFox'


DistinguishedName : CN=FOX Fred,OU=UserAccounts,DC=Manticore,DC=org
Enabled           : True
GivenName         :
Name              : FOX Fred
ObjectClass       : user
ObjectGUID        : db5a3975-980d-4749-b9c0-48aff9217b2a
SamAccountName    : FredFox
SID               : S-1-5-21-759617655-3516038109-1479587680-1314
Surname           :
UserPrincipalName : FredFox@manticore.org

Once you’ve confirmed you have the correct account then pipe it into Set-ADUser and use the –samAccountName parameter:

PS C:\Scripts> Get-ADUser -Identity 'FredFox' | Set-ADUser -SamAccountName 'foxfred' -PassThru


DistinguishedName : CN=FOX Fred,OU=UserAccounts,DC=Manticore,DC=org
Enabled           : True
GivenName         :
Name              : FOX Fred
ObjectClass       : user
ObjectGUID        : db5a3975-980d-4749-b9c0-48aff9217b2a
SamAccountName    : foxfred
SID               : S-1-5-21-759617655-3516038109-1479587680-1314
Surname           :
UserPrincipalName : FredFox@manticore.org

I used the –Passthru parameter so the new account details are shown. Note that the User Principal Name (UPN) isn’t changed. Use the –UserPrincipalName parameter as well if you need to change the UPN at the same time

Posted in PowerShell and Active Directory | Leave a comment

New PowerShell console on Server Core

Server Core is great for reducing the footprint of your VMs – Nano server is smaller but it can’t be a domain controller

One draw back to server core is that you only get a single console. If you hang that for any reason you have to either try and open another one (Hyper-V console greys out CTRL-DEL-ALT) or open a few when you logon to the machine.

You still get a cmd.exe console instead of PowerShell – that should be changed. Its 10 years since PowerShell came along! So run Powershell to open  Powershell in the default console.

“Start-Process -FilePath powershell.exe -Verb RunAS” > new-powershell.ps1

Will create a simple script to open a new elevated Powershell console .

Run it as many times as you want. Perform your work in the new Powershell console and if it hangs – just shut it down. Keep the default console for just opening new PowerShell consoles and then you’ll always be able to keep working.

Posted in Powershell, Windows Server 2012, Windows Server 2012 R2, Windows Server 2016 | Leave a comment

Creating test accounts in Active Directory

There’s often a need to create test accounts in AD. You may want to create a a set of test accounts or if you have a demo/test lab you may need accounts in that. Creating the names for the accounts is a pain unless you go down the test1, test2 etc route.

One way to real looking names is iuse a couple of loops like this

$fnames = @(
'Don'
'James'
'Jason'
'Jeff'
'Steve'
'Will'
'Dave'
'Bill'
'Mick'
'Fred'
)

$lnames = @(
'Jones'
'Smith'
'Brown'
'Black'
'White'
'Green'
'Wood'
'Bell'
'Harris'
'Fox'
)

$secpass = Read-Host -Prompt 'Password' -AsSecureString
$ou = "OU=UserAccounts,DC=Manticore,DC=org"

foreach ($fname in $fnames){
  foreach ($lname in $lnames){
    $name = $lname.TOUpper() + " $fname"
    $sam = "$fname$lname"
    $upn = "$sam@manticore.org"

    New-ADUser -Name $name -SamAccountName $sam -UserPrincipalName $upn -AccountPassword $secpass -Path $ou -Enabled $true
  
  }
}

First create an array of first names & another array of second names

Get a secure string for the Password – I’m using the same password for all as its my demo/test environment

Set the OU you want the accounts in.

Iterate over the set of first names and in that loop iterate over the last name. Within the inner loop create the name, samAccountName and UPN and call New-ADUser.

You end up with a set of new accounts where every first name is joined with every last name to create accounts. Names look a bit samey but for demo environment it works. Also, saves you having to think up individual names.

I’ve used   10 names in each of the first and last name arrays so end up with 100 new accounts.

Posted in PowerShell and Active Directory | Leave a comment

Exploring PowerShell automation

My PowerShell books have all been published by Manning, A while back they asked me to put together a selection of extracts that show the depth and breadth of PowerShell. Its now available – for free – https://www.manning.com/books/exploring-powershell-automation

The book highlights PowerShell remoting and administering SQL Server, IIS and Active Directory through PowerShell. These are core skills these days and the book will give you a good introduction to these areas

Posted in Books, Powershell | Leave a comment

PowerShell 10 year anniversary videos

Yesterday was the PowerShell 10 year anniversary event – broadcast live on channel 9

The session recordings are available

https://channel9.msdn.com/Events/PowerShell-Team/PowerShell-10-Year-Anniversary?sort=status&direction=desc

Posted in Powershell | Leave a comment