Powershell for Cisco?!

Posted: 14th November 2014 by Ben in For the Technical
Tags: , ,

Yeah, I know it’s been a while. I’ve been busy!

Let’s move on from that though. I want to start sharing things again.

First of those things is the “PowerPack” from Cisco!!
Located here

I did mention this is for the Unified Computing System? You don’t know what this is? Ok now you do.

So the amount of cmdlets here are incredible, I think there is somewhere in the 1800 neighborhood.

How do I know that?
(Get-Command | ? {$_.ModuleName -eq “CiscoUcsPS”}).Count

So many possibilities here… I’m normally a “Get” verb guy, when starting out with a new set of cmdlets, so let’s do that:

(Get-Command -Verb “Get” | ? {$_.ModuleName -eq “CiscoUcsPS”}).Count

That is a grand total of 992 items. That is crazy.

Over the next few weeks I’m going to deep dive into a lot of these, so stay tuned.

Recently used my flash drive for a project and when I went to format it again so I can reload an operating system, I noticed it was not utilizing all of the space.

When I went to format it, I saw that it was only showing max: 2.81 gigs (which was the size of the live CD boot I had on there.) I did some digging and found that the system was in fact recognizing the space, however I couldn’t utilize the unused portion.

What I did to fix it was pull open good ol’ disk part.

If you aren’t familiar with diskpart then tread lightly. It’s a very good tool but also very powerful.

Here is how to complete it:

DISKPART> select disk 3
Disk 3 is now selected
DISKPART> clean
Diskpart succeeded in cleaning the disk.
DISKPART>create partition primary
Diskpart succeeded in creating the specified partition
DISKPART>exit

All is good now and I can utilize all the unused space once again.

Hope that helps someone.

I don’t normally post pictures…

Posted: 7th January 2014 by Ben in For the Technical

But this is hilarious:

ITT Tech is two ipconfig and google maps hardcore!
ITT_Hardcore

It’s true, it can’t.
So- you have to download the Vmware OVF Tool

Convert that badboy ovf to a vmx to use in Workstation!

That’s not what you wanted? Oh you are going from vmx to ovf? I’m sorry- here are both ways to do that:
(Assuming you have a environment variable to the ovftool- if not just go to the source C:\Program Files\VMware\…

conversion from vmx to ovf:
ovftool f:/somepath/os.vmx c:\temp\os.ovf

conversion from ovf to vmx:
ovftool f:/somepath/os.ovf c:\temp\os.vmx


Now you are on your way to Virtual Machine goodness!

You sometimes come up with weird desires to do things in programming and scripting and today I needed to increment my filenames not by number, but by alphabet increments. To top it off, not only alphabet entries, but two string alphabet entries! (e.g. aa, ab, ac)

So to start off we have this wonderful tidbit:

$a = 97..122 | foreach {[char]$_}


Ok so that takes care of one part of it, we have a-z and that is a perfect array.
Some of you might wonder why the hell that worked. It’s because the “..” is a range character for powershell. That means that it will print the distance of the specified. So if we didn’t convert that to a character, it would have counted 97-122 in an array (which we stored conveniently).

How did I know that the 97-122 converted to a character would be what I needed?


[int][char]'a'

And you guessed it- I did the same for ‘z’.

So now we need to allow it to count aa, ab, ac and so on and so forth. It took me a minute to logic through this, but if we just duplicate work a bit- we can let powershell do the rest.

$a = 97..122 | foreach {[char]$_}

foreach ($damnNumber in $a)
{
$item = 97..122 | foreach {[char]$_}
foreach ($damnItem in $item)
{
$damnNumber + "" + $damnItem}

Now we can apply that logic to whatever we are working on for the minute.
Hope that helps

Got an email this morning asking for help with a script! I enjoy this! Kind of why I made the site, except I have a terrible memory too and it actually helps me as well.

So here is the email I got this morning, left out the personal information.

Message: Hi

Could you help me with script?
I need list of backup files from folder but my script doesnt work properly.

Get-ChildItem “\\machinename\G:Backup$” | Select-Object Name, CreationTime, @{Name=”Kbytes”;Expression={$_.Length / 1Kb}}

Thanks for help.
Adam

So in looking at this- the Get-ChildItem is the correct commandlet for the job here. We know that Get-ChildItem works like the old school, “dir” command- so this works.

Just looking at the syntax, you may want to check the share name too, usually with a share, I’ve seen a “$” after the G. So in otherwords:
\\machinename\G$\backup$

Just check it though, not sure of your setup. The easiest way would just be to navigate to it through the client computer.

next- Your select statement is awesome. Your label looks great and works like a charm- grats on that.

Adam- another thing to keep in mind is that you must have rights with the account running the script . So if you wrote the script as your user account that doesn’t have rights to the share, right click your powershell ISE or command prompt first and run as a different user and run with admin credentials that have access to the share.

Let me know if that works, doesn’t work!

Got this error recently while trying to run firefox in my Ubuntu server:

Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system.

Being a novice at most linux processes, I didn’t want to just get the fix I wanted to go through the troubleshooting steps.

Obviously there was a problem with a task running, so I took to find a command that would kill processes, simple enough I found a command called kill.

I wasn’t sure which profile the task was running on so I was able to use the command:
killall firefox
And it worked! Gotta be honest, the killall command is pretty sweet sounding anyways..

I’ve had about enough of this…

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System]

Set DisableCMD to 0.

Punks.

So it happens- you are either migrating, updating with a side by side or something just plain happens and you have to restore an existing database to a new machine.

You get your SQL server 2008 R2 install up on a fresh new OS and you get all of your custom settings applied and you restore your database to the machine. Then someone comes back and says it has to be the old name and IP address.

That is no problem.

If you change the NETBIOS name of the machine and change the IP, go ahead and do that now. If you don’t get the person who does that to do that. Rejoin it to the domain then log into your SQL instance(s) one at a time if applicable.

In the instance type: SELECT @@SERVERNAME . Did the name update? Yeah, I didn’t think so.

You will use the system stored procedure:

sp_dropserver <'old_name\instancename'> --(Instance name if applicable once again).
GO

Now that you have dropped the old servername we need to add it back, but we need to make sure the computer knows that it is local:

sp_addserver <'new_name\instancename'>, local
GO

Of course the instance name is applicable as well.

So now you have your machine loaded up- you can also check the jobs to make sure those updated as well:


USE MSDB
GO
SELECT * FROM sysjobs -- this checks the jobs
-- if you need to update them:
UPDATE SYSJOBS SET originating_server = 'newname'

Take it easy now!

Powershell 4.0

Posted: 28th October 2013 by Ben in For the Technical
Tags: ,

It’s released!

I’m going to be jumping into it very soon, but until then:

Read about it!