installed this the other day on a few different computers. great experiences so far for me. i used the guide at the following url. http://www.bwana.org/2009/01/11/how-to-install-windows-7-beta-from-a-usb-drive-to-an-hp-mini-1000-without-vista/

in reply to dennis' comment on my last post on this little thing (http://drowningintechnicaldebt.com/blogs/royashbrook/archive/2009/01/21/create-a-custom-sendto-item-to-process-files.aspx), here's the way to do this with powershell

  1. make sure you have powershell installed and working
  2. create script somewhere with text: foreach ($i in $args) {move-item $i $i.Replace(".mod", ".mpeg")}
  3. create a shortcut in the sendto folder that has the command of '[pathtopowershell.exe] -noexit [pathtoscript]
  4. enjoy!

i was only renaming certain files to certain other files (MOD to MPEG), but obviously you can customize this however you see fit. i had my batch before set not to exit so i could see what was up, but you could take out the -noexit if you wanted it to just run and bail. powershell definitely is more powerful, but IMO still a huge pain for most stuff i would use it for. if most admins invested the amount of time it would take to ramp up using powershell into learning existing tools, they probably wouldn't need it. i'm definitely enjoying playing with it though. here are some references i used:

http://blogs.msdn.com/mikeormond/archive/2008/01/20/powershell-batch-rename.aspx
http://blogs.msdn.com/powershell/
http://sandbox.manning.com/thread.jspa?messageID=62599
http://powershell.wik.is/Cmdlet_Help/Microsoft.PowerShell.Management/Rename-Item
http://adrianba.net/archive/2007/10/29/rename-item-and-square-brackets-in-powershell-no--literalpath.aspx

 

how i have lived this long in my life without familiarity with these commands is beyond me. i'm a big fan of the command line especially commands that are already or mostly built in. these come with the admin pack. so much easier than opening up the ad user group mgr and other gui tools. here's a sample command.

dsquery group -name "any domain group in your domain" | dsget group -members |dsget user -email -samid -display

this command will pipe the full name to the get command to list the members which pipes to the command to show the email, samid, and the display name. obviously tons of different ways to do everything, but this is something i have been using a lot as normally when i open the ad tools it is to get similar simple details, not to do things that that tool really excels at. to me anyway.

dsquery user -samid "domainid" | dsget user -memberof | dsget group -samid

list group memberships for a user using the group samid.

Posted 05-18-2009 1:56 PM by royashbrook | with no comments
Filed under:
Login and show basic info

require 'soap/wsdlDriver'
require 'digest/md5'
u = "user"
p = Digest::MD5.hexdigest("password")
ua = {"user_name" => u,"password" => p}
wsdl = "http://yoursite.com/soap.php?wsdl"

#create soap
s = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver

#uncomment this line for debugging. saves xml packets to files
#s.wiredump_file_base = "soapresult"

#create session
ss = s.login(ua,nil)

#check for login errors
if ss.error.number.to_i != 0 

	#status message
	puts "failed to login - #{ss.error.description}"
	
	#exit program
	exit
else

	#get id
	sid = ss['id']

	#get current user id
	uid = s.get_user_id(sid)
	
	#status message
	puts "logged in to session #{sid} as #{u} (#{uid}) "
	
	#logout
	s.logout(sid)
	
	#status message
	puts "logged out"
end

Adding an account
After login, you can create new accounts using the code :
        module_name = "Accounts"    
        name_value_list =  [ { "name" => "name", "value" => "theworldcompany" },
                             { "name" => "phone_office", "value" => "01234567" } ]
        s.set_entry(sid, module_name,  name_value_list)
Posted 03-15-2009 4:01 PM by royashbrook | with no comments
Filed under:
so i have this video camera and it records files to mod files. i dunno why. mod's are just like mpegs. you can just rename them and open them. i don't know why they aren't just saved as mpegs, but whatever. so i got tired of dropping out to dos and just renaming the files so i could review them. i could also i'm sure find a way to just register mod files with my computer but bah. i decided to just create a custom sendto item so i could just mass rename them. so if you want to rename a bunch of files or really do anything to a bunch of files, you can create a file called whateveryouwant.cmd and put it in your sendto folder inside of your profile folder. then i used the text:

:loop
ren %1 *.mpeg
shift
if %1. NEQ . goto loop

in the file. you could replace the ren command with whatever you want. %1 should be the current file. anyway, if anyone finds this and it doesn't make sense, just comment and i'll clarify.

thanks to this article for the base script. i needed to get a list of all users and the roles they had in each db. this script is great in that you can use the raw base script (mine is slightly modified) and list things for every object instead of just at the db level. in my case and in most people's case i imagine that makes this dataset rather large. this allowed me to get a large union on the raw data i needed for all of the databases and then i could put it one table so i could work with it to restructure a lot of permissions without having to requery over and over again. i don't have sa rights so this also gave me the ability to ask for sa rights briefly in order to accomplish this and then i could be taken off. if you had a less nice sa, this should give you the ability to give them something that only takes them like 10 minutes to do. =)

 mostly like all things i'm just posting this so i don't forget it ha!

 I just did this: sp_msforeachdb 'print  ''USE ?GO WITH    perms_cte as(        select USER_NAME(p.grantee_principal_id) AS principal_name,                dp.principal_id,                dp.type_desc AS principal_type_desc,                p.class_desc,                OBJECT_NAME(p.major_id) AS object_name,                p.permission_name,                p.state_desc AS permission_state_desc         from    ?.sys.database_permissions p        inner   JOIN ?.sys.database_principals dp        on     p.grantee_principal_id = dp.principal_id            where class_desc is null)--usersSELECT * INTO somewhere.DBO.R1_? FROM (SELECT [db]=db_name(), p.principal_name,  p.principal_type_desc, p.class_desc, p.[object_name], p.permission_name, p.permission_state_desc, cast(NULL as sysname) as role_nameFROM    perms_cte pWHERE   principal_type_desc <> ''''DATABASE_ROLE''''UNION--role membersSELECT [db]=db_name(),rm.member_principal_name, rm.principal_type_desc, p.class_desc, p.object_name, p.permission_name, p.permission_state_desc,rm.role_nameFROM    perms_cte pright outer JOIN (    select role_principal_id, dp.type_desc as principal_type_desc, member_principal_id,user_name(member_principal_id) as member_principal_name,user_name(role_principal_id) as role_name--,*    from    ?.sys.database_role_members rm    INNER   JOIN ?.sys.database_principals dp    ON     rm.member_principal_id = dp.principal_id) rmON     rm.role_principal_id = p.principal_id) X''' Then ran the results to get the data for each db, then I ran this: sp_msforeachdb 'print ''UNION ALL SELECT * FROM somewhere.DBO.R1_? '' ' 

and removed the first union and I had my data. Plus I have all the root tables in the somewhere database to work with temporarily.

 

Posted 09-05-2008 3:19 PM by royashbrook | with no comments
Filed under:


oh nos!!!11!!

Posted 08-01-2008 11:32 AM by royashbrook | with no comments
Filed under:

it's depressing to me how many people that i run into today that have an excrutiatingly limited knowledge about the command line in windows, and yet they are considered experts on the platform. that aside, i figured i would share a couple of very simple uses.

something people ask a lot is what domain groups they are in. you can run 'net user %username% /domain' from the command line to see what domain groups you are in. it does cut off the names if they are too long, so the ad tools are better or using vbscript to query, but this is quick and easy for general use. there are other uses for this command, but this is the one i use the most often. you can replace %username% with anyone in the domain's ids to view this info. there are some limitations, but it's useful.

another thing that comes up in minor administration tasks is the ability to add a bunch of people at once. you can of course use this with the gui, but if you are already at the command line, you could do something like this on the machine:

net localgroup somegroup /add

net localgroup somegroup user1 user2 user3 user4 user5 /add

the above commands will add somegroup as a localgroup and then add users 1 through 5 to that localgroup. you can add local users or domain users (via domain\user) or domain groups.

if it was a sql box, you could then osql locally and run some commands to add them as some role.

CREATE LOGIN [%whatever your machien name is%\%whatever your local group name is%] FROM WINDOWS WITH DEFAULT_DATABASE=[tempdb]
EXEC master..sp_addsrvrolemember @loginame = N'%whatever your machien name is%\%whatever your local group name is%', @rolename = N'sysadmin' (or whatever role you want to give them)

 

there you go. how to add a local group, a bunch of users, and even set them up in sql as some role in like 2 minutes from the command line without waiting for stupid computer manager or sql mgmt studio to open. =)

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}

System.Security.SecurityExceptions will always be … well some kind of security problem ;)

 

Running .net exes over the network requires different .net perms. You can see the perms an assembly requires using permcalc from the .net sdk. It used to be called… I think permview.

 

You can run caspol –rs[g/p] %path to assembly% to see some info on the permissions. G will show you the groups it belongs to in the gac, P will list the permissions.

 

 

From: xxxxxxxxxxxxxxx
Sent: Thursday, July 17, 2008 5:40 PM
To: Ashbrook, Roy
Subject: question

 

Whats up roy… any idea why I’m getting this error xxxxxxxxxxxx

 

 

Microsoft Windows XP [Version 5.1.2600]

(C) Copyright 1985-2001 Microsoft Corp.

 

C:\WINNT>\\server\dotnetapp.exe

 

Unhandled Exception: System.Security.SecurityException: That assembly does not a

llow partially trusted callers.

   at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly a

sm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, Secur

ityAction action, Object demand, IPermission permThatFailed)

   at ....

 

Posted 07-18-2008 11:54 AM by royashbrook | with no comments
Filed under:

"fairness is a concept that was invented so that children and idiots could participate in arguments"

 -- Scott Adams

Posted 07-13-2008 2:13 PM by royashbrook | with no comments
Filed under:

so i needed to count the lines of a bunch of different filetypes in a folder. i decided to try using linq for this. here's what i came up with. basically a single linq statement =P

you can tune the regex to taste. i just said (i think, i'm not a regex wizard) something that isn't a newline (.+) and the line terminators i'm using (\r\n).

 

using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;

namespace LineCounter
{
    class LineCounter
    {
        static void Main(string[] args)
        {
            // dir to search
            string d = @"c:\pathtocode";

            // regex match for newlines
            string lf = @".+\r\n";
           
            // get the file list with directory
            string[] f = Directory.GetFiles(d, "*.*", SearchOption.AllDirectories);

            // filter to only get these files
            string filter = ".cs,.resx,.sql,.htm,.html,.xml,.xsl,.xslt";

            // count total lines
            int lines = (
                    from name in f
                    where filter.Contains(Path.GetExtension(name.ToLower()))
                    select new
                    {
                        length = Regex.Matches(
                            new StreamReader(name).ReadToEnd(), lf).Count
                    }
                ).Sum(a => a.length);

            // write out the total lines
            Console.WriteLine(lines);

            Console.ReadLine();
        }
    }
}
 

Stack q = new Stack();
q.Push(argument);
while (q.Count > 0)
{
    string d = q.Pop().ToString();
    Console.WriteLine(d);
    foreach (string sd in Directory.GetDirectories(d))
        q.Push(sd);
}

Posted 06-10-2008 2:41 PM by royashbrook | with no comments
Filed under: ,

My thoughts on the Microsoft CAB?

Ah... the CAB. It's like a 40 story building crafted completely out of butter. A historic architectural feat to be sure, but ultimately pretty useless and messy after you use it for a while.

 

=)

select
    case when dbid = 32767
        then 'resource'
        else db_name(dbid)
    end [db_name]
    , object_schema_name(objectid,dbid) [schema_name]
    , object_name(objectid,dbid) [object_name]
    , sum(usecounts) [executions]
    , max(max_execution_time) [last_execution_time]
    , sum(total_logical_reads) [total_logical_reads]
    , sum(total_logical_reads) / sum(usecounts) * 1.0 [avg_logical_reads]
    , sum(total_elapsed_time) / 1000 [total_elapsed_time_ms]
    , ( sum(total_elapsed_time) / sum(usecounts) * 1.0 ) / 1000 [avg_elapsed_time_ms]
from
    sys.dm_exec_cached_plans cp
    cross apply sys.dm_exec_sql_text(cp.plan_handle) qt
    join (
        select
            plan_handle
            , max(last_execution_time) [max_execution_time]
            , sum(total_elapsed_time) [total_elapsed_time]
            , sum(total_logical_reads) [total_logical_reads]
        from
            sys.dm_exec_query_stats
        group by
            plan_handle
        ) r on r.plan_handle = cp.plan_handle
where
    objtype = 'Proc'
    and qt.text LIKE '%create%proc%'
    --and db_name(dbid) = 'some_database'
    --and object_name(objectid,dbid) = 'some_stored_procedure'
group by
    dbid, objectid
order by
    db_name(dbid), object_name(objectid,dbid)

 

thanks to this article for the inspiration.

Posted 03-21-2008 4:57 PM by royashbrook | with no comments
Filed under: ,
More Posts Next page »