Skip to main content

Posts

Showing posts from April, 2015

Renaming Remote Clients

So I am finally getting around to posting some of the code from this weeks PowerShell class.  As always, I’m listening to my class and I am not afraid to deviate from the lessons when someone comes up with a good idea.  While teaching about PowerShell remoting, I was asked if it is possible to rename remote clients.  Sure it is! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 $Cred = Get-Credential -Credential MCTExpert\AdminAccount $OldName = "CL1" $NewName = "Client1"   Invoke-Command -ComputerName $OldName -ScriptBlock {     Param ( $C , $NN )     $Name = HostName     $Splat = @{         "NewName" = $NN         "Restart" = $True         "Force" = $True         "PassThru" = $True         "DomainCredential" = $C     }         Rename-Computer @Splat   } -ArgumentList $Cred , $NewName Line Details 1 Ask for the domain credentials of someone who h

Highlight Unknown Commands in Sapien PowerShell Studio

OK, so I should not be working right now.  It is Friday.  I just finished teaching a 5 day Windows Server 2012 R2 class.  It is sunny and 86 degrees.  I should be outside or something.  Like the nerd I am, this Navy Chief is hard at work. Albeit, in shorts and no shoes or socks since I am at home.  Anyway, I took a quick look at the forms at PowerShell.com and noticed the stream about having bold face type in the ISE.  I like the PowerShell ISE.  It is fast and simple.  That also means that it is light on the bells and whistles. I also use Sapien’s PowerShell Studio 2015 so I decided to publish out one of my personal settings.  Take a look at the Font and Color settings below. The item is Unknown Command it is also the only item with a background color other that the editors background, which for me is black.  I normally use TAB completion heavily, but I also do some weird stuff where TAB completion is not the best idea.  So, every once and a while, I make a typo.  Having the Unknow

Pulling the Last Logged on User from Your Clients

Yesterday on PowerShell.com, I had the opportunity to help an IT Pro pull the last logged on user from every one of their client machines.  What we discovered is that there are two places in the registry that hold this information.  For the last local account, we extracted the name from: HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUsername For the last domain user: HKLM:\Software\Microsoft\windows\currentVersion\Authentication\LogonUI\LastLoggedOnUser Just to add a little, and since it was right there, here is the last SID: HKLM:\Software\Microsoft\windows\currentVersion\Authentication\LogonUI\LastLoggedOnUserSid To do this one at a time would have been to time consuming.  Also, what about the clients that were not online?  How are you going to record them?  Sitting in my Windows Server 2012 R2 class right now is an IT Pro with over 70,000 clients.  This would have been a nightmare to perform manually.  I am estimating that it would have taken about a minu