Uncategorized
Learn to Love, Love to Learn
I’ve been in the technology field now for over 15 years. I must say that I’ve been extremely fortunate and believe that while I’ve only had a handful of jobs, I’ve made the right decision to move on when the opportunity has presented itself. But my story could be very different.
At this point in my life, finally, I love learning. Well, I love it again. Most of that probably has to do with my wife (and children) but I realize that I’ve loved it for a while and at some point just lost my way. I did well in high school without really applying myself. But when I got ready to graduate and decide on what I wanted to go to college for I wasn’t really sure. I had been tinkering with computers for a while, owned a few Java 1.0 and HTML books and had been ‘the guy’ for friends and family PC issues. I enjoyed technology. I enjoyed learning about what was next. But for a career? I just wasn’t sure.
That’s when my dad gave me the worst advice ever:
You don’t want to go to school for computers. You’ll always have to be learning and studying.
Looking back on this, it stings a little (okay, a lot). I took this advice and said, you know what, you’re right. Who wants to have to be in school all the time learning new things. Or constantly reading books (even though I was an avid reader) to learn how to do something new. So I went to school and floundered. The truly engaging classes I excelled in. The ho-hum classes I tried not to sleep through. Three major changes later, I was in the Comp-Sci program and burnt out on college. So I quit. But college isn’t the issue or my lack of focus the first time around.
You see, we are teaching our kids to love learning. To enjoy what they don’t yet know. And we certainly live in an age where information is right at their fingertips. They don’t fathom having to go to the library to look up something in an encyclopedia. They don’t know what it’s like to not have information instantly available, to have an inquiry and be able to search out info from multiple sources. But my dad took that away. With one sentence, he made me think that learning was one and done. Like sitting in math class and thinking you’ll never use this in ‘the real world’. 😉
At this point in my life I have found the love again. I read as much as possible and watch all the lovely videos on Pluralsight that I can. I model this for my children and when they ask questions I don’t know the answers to, we look them up. But I will never tell my children to bypass what they love to do what’s easier, especially if it involves learning.
Using Credentials to Get Remote PowerShell Connection to Exchange Connection
Saw this come across the search logs so I figured I’d detail the steps needed to supply credentials to a remote PowerShell connection to Exchange. Since we’re connecting to another system to run the Exchange PS cmdlets, and we are not loading a PSSnapin, the remote system needs to have those cmdlets available. I’m also separating this out into individual methods for easy re-use.
To setup a remote connection, we need to create a new WSManConnectionInfo object. We’re specifically going to use the constructor that takes a Uri for the connection endpoint, a string value for the Uri of the shell and the credentials we want to use.
WSManConnectionInfo Constructor (Uri, String, PSCredential)
The Uri will be specific to your situation and will look something like this : http://myexchangeserver.domain.corp/powershellThe shell is pretty simple. In this case it is : http://scemas.microsoft.com/powershell/Microsoft.Exchange
And last but not least it the PSCredential needed for the connection. PSCredential takes a string for the Username and a SecureString for the password. Here’s an small method to pass in a string and get a SecureString back :
SecureString GetSecurePassword(string password) { var securePassword = new SecureString(); foreach (var c in password) { securePassword.AppendChar(c); } return securePassword; }
With that out of the way, let’s take a look at a snippet for getting the connection info :
WSManConnectionInfo GetConnectionInfo() { var securePassword = GetSecurePassword(password); var cred = new PSCredential(username, securePassword); var connectionInfo = new WSManConnectionInfo(new Uri("http://superserver.corp/powershell), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", cred); connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Credssp; //or Basic, Digest, Kerberos etc. return connectionInfo; }
Now let’s put it all together to make a remote connection :
using (var runspace = RunspaceFactory.CreateRunspace(connectionInfo)) { using (var ps = System.Management.Automation.PowerShell.Create()) { //psCommand was created above ps.Commands = psCommand; runspace.Open(); ps.Runspace = runspace; try { var results = ps.Invoke(); if (!ps.HadErrors) { runspace.Close(); //Yay! no errors. Do something else? } catch (RemoteException ex) { //error handling here } } }
So, a couple of things to mention here. First, psCommand was created like this. You could also create a Pipeline if you have more than one command to run or even use it to create a PS script to run. Also, if you need to do something with the results of the command, well, you’ll have to either make this return the results ((FavoriteCollectionType) or modify this to suit your needs. Second, we verify that the command had no errors (no exception but didn’t run successfully for whatever reason) but that’s it. Might want to expand here or in the calling method.
I hope this has been informative. 😀
Moving WSUS Databases
Most important piece of information….SQL Server name:
\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query
Detach database, move files, re-attach database.
Moving WSUS content:
C:\Program Files\Update Services\Tools\wsusutil.exe movecontent “Content destination” “logfile destination”
Ex.
C:\Program Files\Update Services\Tools\wsusutil.exe movecontent W:\WSUS W:\MoveContent.log