Saturday, October 17, 2009

ListWmiNamespaces.ps1

# This is a example taken from the book "Microsoft Windows Powershell Step by step"


$wmi = Get-WmiObject -class __Namespace -namespace root
"Listing namespaces on " + $wmi[0].__server +
" please wait a second "
for ($i=0;$i -le $wmi.length;$i++)
{if ($i -lt $wmi.length)
{Write-Host -noNewLine "."
Start-Sleep -m 75}
else
{Write-Host "."}
}

$wmi | Format-List name
Write-Host -foregroundColor green "There are" $wmi.length `
"namespaces on this machine `n"

GetCPUinfo.ps1

# This is a example taken from the book "Microsoft Windows Powershell Step by step"


$wmi = get-wmiObject win32_processor
if ($wmi.Architecture -eq 0)
{"This is an x86 computer"}
elseif($wmi.architecture -eq 1)
{"This is an MIPS computer"}
elseif($wmi.architecture -eq 2)
{"This is an Alapha computer"}
elseif($wmi.architecture -eq 3)
{"This is an PowerPC computer"}
elseif($wmi.architecture -eq 6)
{"This is an IPF computer"}
elseif($wmi.architecture -eq 9)
{"This is an x64 computer"}
else
{$wmi.architecture + " is not a cpu type I am familiar with"}
"Current clockspeed is : " + $wmi.CurrentClockSpeed + " MHZ"
"Max clockspeed is : " + $wmi.MaxClockSpeed + " MHZ"
"Current load percentage is: " + $wmi.LoadPercentage + " Percent"
"The L2 cache size is: " + $wmi.L2CacheSize + " KB"

DisplayComputerRoles.ps1

# This is a example taken from the book "Microsoft Windows Powershell Step by step"




$wmi = get-wmiobject win32_computersystem
"computer " + $wmi.name + " is: "
switch ($wmi.domainrole)
{
0 {"`t Stand alone workstation"}
1 {"`t Member workstation"}
2 {"`t Stand alone server"}
3 {"`t Member server"}
4 {"`t Back up domain controller"}
5 {"`t Primary domain controller"}
default {"`t The role can not be determined"}
}

Sunday, October 11, 2009

RTR record keeping application

Just a small RTR record keeping application. It uses xml. You just need to download and run it. Thats all. Built on C# 2008.

Download it from:-

http://www.esnips.com/doc/23b9e54d-e3ec-4e14-bb85-72d81523beee/RTRApplication1

Wednesday, October 7, 2009

Function to test whether 2 array of objects are equal or not.

public static bool AreEqual(object[] o1, object[] o2)
{
if (o1 == null && o2 == null)
{
return true;
}
if (o1 == null || o2 == null)
{
return false;
}

if (o1.Length == o2.Length)
{
int i;
bool eq = true;
for (i = 0; i
{
if (AreNotEqual(o1[i], o2[i]))
{
return false;
}
}

return eq;
}

return false;
}

Function to test whether 2 objects are equal or not.

public static bool AreEqual(object o1, object o2)
{
if (o1 == null && o2 == null)
{
return true;
}
if (o1 == null || o2 == null)
{
return false;
}
if (o1.GetType().FullName != o2.GetType().FullName)
{
return false;
}
return o1.Equals(o2);
}


//ofcourse Are not equal can be done just by negating the above function

public static bool AreNotEqual(object o1, object o2)
{
return !AreEqual(o1, o2);
}

Saturday, October 3, 2009

Aliases in PowerShell

Name Definition
ac Add-Content
asnp Add-PSSnapin
clc Clear-Content
cli Clear-Item
clp Clear-ItemProperty
clv Clear-Variable
cpi Copy-Item
cpp Copy-ItemProperty
cvpa Convert-Path
diff Compare-Object
epalExport-Alias
epcsvExport-Csv
fcFormat-Custom
flFormat-List
foreachForEach-Object
%ForEach-Object
ftFormat-Table
fwFormat-Wide
galGet-Alias
gcGet-Content
gciGet-ChildItem
gcmGet-Command
gdrGet-PSDrive
ghyGet-History
giGet-Item
glGet-Location
gmGet-Member
gpGet-ItemProperty
gpsGet-Process
groupGroup-Object
gsvGet-Service
gsnpGet-PSSnapin
guGet-Unique
gvGet-Variable
gwmiGet-WmiObject
iexInvoke-Expression
ihyInvoke-History
iiInvoke-Item
ipalImport-Alias
ipcsvImport-Csv
miMove-Item
mpMove-ItemProperty
nalNew-Alias
ndrNew-PSDrive
niNew-Item
nvNew-Variable
ohOut-Host
rdrRemove-PSDrive
riRemove-Item
rniRename-Item
rnpRename-ItemProperty
rpRemove-ItemProperty
rsnpRemove-PSSnapin
rvRemove-Variable
rvpaResolve-Path
salSet-Alias
sasvStart-Service
scSet-Content
selectSelect-Object
siSet-Item
slSet-Location
sleepStart-Sleep
sortSort-Object
spSet-ItemProperty
sppsStop-Process
spsvStop-Service
svSet-Variable
teeTee-Object
whereWhere-Object
?Where-Object
writeWrite-Output
catGet-Content
cdSet-Location
clearClear-Host
cpCopy-Item
hGet-History
historyGet-History
killStop-Process
lpOut-Printer
lsGet-ChildItem
mountNew-PSDrive
mvMove-Item
popdPop-Location
psGet-Process
pushdPush-Location
pwdGet-Location
rInvoke-History
rmRemove-Item
rmdirRemove-Item
echoWrite-Output
clsClear-Host
chdirSet-Location
copyCopy-Item
delRemove-Item
dirGet-ChildItem
eraseRemove-Item
moveMove-Item
rdRemove-Item
renRename-Item
setSet-Variable
typeGet-Content

Node.JS rest api Tutorials