Top

How to Start a Process as Administrator

So I find this one to be rather useful. I probably use it nearly every day. The syntax is simple the results are powerful. How to start a process as administrator in powershell.

  1. Open Powershell Console (doesn’t need to be admin) or the windows run prompt (win+R):
  2. Use the following Command Syntax to launch a process as admin:
    1. Start-Process ProcessName -Verb runas
  3. Example:
    1. Start-Process Powershell -Verb runas

 

powershell_start_process_as_administrator

jklann

How To Delete a Project from Team Foundation Server

I came across this one today while working on a new set up of TFS 2015. I created a Team Porject as a test and found that it could not be deleted. So we stumbled across an alternative way of deleting the project without having to sign into the actual application server.

 

Run this from admin command prompt where your Visual Studio is install:

  1. Windows 10 VS 2015 Pro path:
    1. C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\
  2. Command
    1. TfsDeleteProject.exe /force /collection:http://TFSServerName:PORT/tfs ProjectNameToBeDeleted
  3. Then Enter Y  at the prompt to confirm the project deletion.

 

 

team_foundation_server_delete_project_command

 

jklann

Easily Manage a Service on a Remote Machine

For this example I will use Windows Remote Desktop Services and their ever needing service restart.

  1. Remote Restart Service
    1. Syntax
    2. Get-Service -ComputerName yourremotecomputername -Name servicename | Restart-Service
      
    3. Example (Restart Remote Desktop Services)
    4. Get-Service -ComputerName server1.domain.local -Name TermService | Restart-Service -Force
      
    5. The “-Force” is added to the end as TermSerivce has dependent services and this flag is required to restart TermSerivce as well as its depedencies
  2. From here you can explore other Service commands and options using this base syntax to get the service object on a remote machine.

 

jklann

Postgres How To Get List of Functions Like PGAdmin III

Recently I had the need to get a bunch of object stats and counts of two postgres databases to compare them. The goal was to confirm both via query results as well as visually via PGAdmin III, just in case I missed something in excel :P. Anyways I quickly realized that some of my object counts did not match the UI counts. After a little playing with the query I realized the UI splits the Functions into aggregates, functions, and trigger functions. However by default the UI hides the views for aggregates and trigger functions and you have to manually specify these to be shown in schema tree.

File -> Options
pg_admin_III_file_options

Browser -> Display -> Objects
pg_admin_III_file_options_browser_display_objects

So If you are wanting to get only user functions like the list that is in PGAdmin III under each schema in the function tree. You will want to remember to exclude aggregate functions and trigger functions.

This Query does just that. It gets the count of functions per schema just like displayed in the UI.

select ns.nspname, count(*)
from pg_proc pr
join pg_namespace ns on 
    pr.pronamespace = ns.oid
--Exlcude system schemas
where ns.nspname <> 'pg_catalog' 
    and ns.nspname <> 'information_schema' 
    --Exclude Trigger Functions
    and pr.oid not in 
        (select tgfoid from pg_trigger)
    --Exclude aggregate functions
    and pr.proisagg = 'f'
group by ns.nspname
order by ns.nspname;

This Query Gets a count of Aggregate functions per schema.

select ns.nspname, count(*)
from pg_proc pr
join pg_namespace ns on 
      pr.pronamespace = ns.oid
--Exlcude system schemas
where ns.nspname <> 'pg_catalog' 
    and ns.nspname <> 'information_schema' 
    --Exclude Trigger Functions
    and pr.oid not in 
         (select tgfoid from pg_trigger)
    --include aggregate functions
    and pr.proisagg = 't'
group by ns.nspname
order by ns.nspname

Lastly this Query Gets a count of Trigger functions per schema.

select ns.nspname, count(*)
from pg_proc pr
join pg_namespace ns on 
    pr.pronamespace = ns.oid
--Exlcude system schemas
where ns.nspname <> 'pg_catalog' 
    and ns.nspname <> 'information_schema' 
    --Include Trigger Functions
    and pr.oid in
         (select tgfoid from pg_trigger)
group by ns.nspname
order by ns.nspname

Now you have a set of Function count queries that will match the PGAdmin III UI.

jklann
sqlThemeSmall

SQL Sever Management Studio 2014 Custom Solarized Theme (JK_Solar)

I was looking for a really good SQL Sever Management Studio Solarized theme and I found it rather difficult to find any themes that were created specifically for SQL Sever Management Studio. There are a lot of Visual Studio themes that are out there that you can load but the syntax highlight for TSQL was never great. So I took some colors from a collection of Visual Studio themes and created a custom SQL Sever Management Studio theme specially for TSQL. You can find the download link to the vssettings Theme file below. I haven’t tested this with any other version of SQL Sever Management Studio other than 2014 but I don’t see why it wouldn’t work on earlier versions.

JK_Solar SSMS Theme

JK_Solar SSMS Theme

To import this theme into SSMS follow these steps:

  1. Open the Tools menu and select Import and Export Settings.
  2. Select Import selected environment settings then click Next.
  3. Select a place to backup your current settings.
  4. Select the JK_Solar.vssettings file you downloaded then click Next.
  5. Click Finish and you’re done!

Download Link: JK_Solarized.vssettings Count: 1,561 FileSize: 1.9 kB

Link to Script in Screen Capture: Stack Overflow Script

jklann
sqlCode

SQL Convert Size in Bytes to Human Readable Units

Came across a lot of databases that hold size of objects, files, whatever in bytes which is not the easiest to glance at and easily understand. So I wrote a basic SQL function to convert size in bytes to human readable format. The goal being that the output is greater than or equal to 1.0, that is automatically gets loops until it is less than 1.0 then stops at the previous division allowing for an easy to understand yet automatic format. I also have it round to 2 decimal places.

--set database to be used
--USE BEDB;
--checks if function already exists if it does it drops and re-adds it otherwise it adds it
IF OBJECT_ID (N'dbo.f_ConvertSize') IS NOT NULL
    BEGIN
        DROP FUNCTION Dbo.F_ConvertSize;
        PRINT 'Function f_ConvertSize Alread Exists, Deleting it and Adding it back now'
    END
ELSE
    BEGIN
        PRINT 'Function f_ConvertSize Does Not Exist, Adding it now.'
    END

GO
--creates function that
--parameter: size in bytes
--returns: single value nvarchar of converted size to readable format
CREATE FUNCTION Dbo.F_ConvertSize ( @rawSize FLOAT )
Returns NVARCHAR(12)
    BEGIN
        --creates processing variables
        --div = value to divide by
        --counter = number of times divided
        DECLARE @div INT,@counter INT
        --unit is used to capture the unit measure used in the output
        DECLARE @unit NVARCHAR(3)
        --the sizes table variable is used to store the different units
        DECLARE @sizes TABLE (Id INT,Unit NVARCHAR(3))
        INSERT @sizes(Id,Unit)
        VALUES(1,' B'),(2,' KB'),(3,' MB'),(4,' GB'),(5,' TB')
        --sets div and counter
        SET @div = 1024
        SET @counter = 1
        --while loop used to perform the conversion with condition clause that requires the size to be greater or equal to 1
        WHILE @rawSize >= 1 AND @counter <= 5
            BEGIN
                --breaks if the size is less than 1 after division
                --else it sets the rawsize to the rawsize divided by the div then it sets the counter to +=1
                IF @rawSize/@div < 1
                    BREAK
                ELSE
                    SET @rawSize = @rawSize/@div
                    SET @counter += 1
            END
        --gets units used from the units table variable
        SELECT @unit = Unit
        FROM @sizes
        WHERE Id = @counter
        --converts the new size to varchar and rounds it to 2 decimal places then adds the units and returns the output
        RETURN CAST(ROUND(@rawSize,2) AS NVARCHAR(50))+@unit
    END
jklann
speed_and_duplex_values_advanced_tab_adapter_configurations

How to tell if a NIC is using full or half duplex

  1. Open windows Network and Sharing Center.  My favorite way to do this in Windows 7 is to right click on the network icon in the right system try and select “Open Network and Sharing Center”. If you are using Windows 8 press the windows key and search for Network and Sharing Center.
    1. tray_open_network_and_sharing
  2. Once in the Network and Sharing Center in the left menu select the “Change adapter settings” link.
    1. change_adapter_settings_network_and_sharing
  3. Now in the “Network Connections” Window Select the NIC that you want to check the duplex on. Normally this is the Local Area Connection unless you have multiple NICs then choose the one you want to check, right click and select properties
    1. adapter_properties_network_connections
  4. In the new Window click configure 
    1. configure_adapter_properties
  5. In the new Windows select the Advanced tab. Then in the Property box scroll down and find the list item Speed & Duplex  then click it. In the right drop down labeled Value  you will see what the NIC is set too. By Default it is Set to Auto Negotiation. From here you can drop down and select your speed and duplex for that NIC.
    1. speed_and_duplex_values_advanced_tab_adapter_configurations

 

 

jklann

How to display HTML code in an adobe flex desktop application the Easy Way

So am very new to adobe flex and really don’t plan on using it that much other than to generate a quick ui for something simple.

In this case I wanted to use flex to create a small desktop app to load a live monitor website. In this case the default <mx:HTML location=”http://site.com” was not loading the site at all so was digging all over the place for a solution. I came across expensive libraries that could do it, and a pretty cool github project called Flex-iFrame if you want to get complicated with it. Needless to say I came up with my own solution.

The idea is that the <mx:HTML location=”  can point to a location html file as well. So I wrote a quick html page with an iframe to the website I wanted to monitor. Next I copied the html file to the /src/ directory of the adobe flex project folder.  Finally I added the line <mx:HTML location=”myhtmlfile.html” /> . This worked great for my application and seems to be the easiest way to perform this process.

Steps:

1.)  Create your adobe flex project:

create_new_flex_project

create_new_flex_project

2.)  Name the projected whatever you want and be sure to select the Application type as Desktop then select finish:

create_new_flex_project_settings

create_new_flex_project_settings

3.)  Next create the html file with the html you want to display in my case an iframe:

<html>
<head>
</head>
<body>
<iframe src=”https://site.com/livemonitoring/stuff/display&type=Grid height=”400px”></ifram>
</body>
</html>

Note:  you can add jquery and css file links as well if they are local to your system make sure you copy them with the html file in the next step.

4.)  Now that you have created the html file copy it and any other dependent files to your flex projects src directory. Typically the path will be something like:

C:\users\username\adobe flash builder 4.7\ProjectName\src

Note: This is also the directory where the projects  .mxml and  -app.xml  will be located.

5.) The last part for this will be to add the flex html location code to view the file add something like the following to your flex project.

<mx:HTML location=”yourhtmlfile.html” />

 

flex_html_code

flex_html_code

 

Note: From  here you can build the rest of your app and style it the way you would like.

6.) Finally run your app!

flex_html_app_running

flex_html_app_running

 

jklann