2010/12/23

Powershell - Using String Functions

 

Source: http://powershell.com/cs/blogs/tips/archive/2009/06/08/using-string-functions.aspx

PowerShell uses .NET objects everywhere. Anything is represented as .NET object, and .NET objects come with useful built-in methods. However, for string manipulation you do not need to look for sophisticated external commands as they are built right into strings.

Here are a couple of useful examples:

"Hello".ToLower()
"Hello".ToUpper()
"Hello".EndsWith('lo')
"Hello".StartsWith('he')
"Hello".toLower().StartsWith('he')
"Hello".Contains('l')
"Hello".LastIndexOf('l')
"Hello".IndexOf('l')
"Hello".Substring(3)
"Hello".Substring(3,1)
"Hello".Insert(3, "INSERTED")
"Hello".Length
"Hello".Replace('l', 'x')
"Server1,Server2,Server3".Split(',')
" remove space at ends ".Trim()
" remove space at ends ".Trim(' rem')

Rename a network card in Command Line

Last week i was working on HP RDP (Rapid Deployment Pack), we want to automate the deployment of new server (Mainly Physical, and some Virtual)

I was looking for a way to rename an network Interface, by default: "Local Area Connection" or "Local Area Connection 2". Here is the useful command:

netsh interface set interface name="Local Area Connection" newname="ExampleLan"

2010/12/21

MS Windows Server 2008 R2 - Desktop Icons

Have you noticed that you cannot add the desktop icons (Computer, Network, etc.) to your Windows Server 2008 R2 desktop? Am I the only one who is annoyed by this? If not, here's how to get them back.

First, you'll have to go into Server Manager and access the Features section. In Features, you will select to add a feature and then select the Desktop Experience feature. Once added, you will have to reboot the server. That's right! A reboot is required to add icons to your desktop.

Now this is really insane. Think about it. You can add your own icons for shortcuts on the desktop, but to get Computer and Network, you have to add the entire Desktop Experience feature. What a ridiculous decision Microsoft made here.

Now that I've expressed my suffering, we shall move on.
Once you've rebooted the server, simply right-click on the Desktop and select Personalize. From here, you can add the desktop icons you desire as usual.

OK. I'm over it now, but it's still ridiculous.