# 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"
Saturday, October 17, 2009
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"
$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"}
}
$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
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 |
epal | Export-Alias |
epcsv | Export-Csv |
fc | Format-Custom |
fl | Format-List |
foreach | ForEach-Object |
% | ForEach-Object |
ft | Format-Table |
fw | Format-Wide |
gal | Get-Alias |
gc | Get-Content |
gci | Get-ChildItem |
gcm | Get-Command |
gdr | Get-PSDrive |
ghy | Get-History |
gi | Get-Item |
gl | Get-Location |
gm | Get-Member |
gp | Get-ItemProperty |
gps | Get-Process |
group | Group-Object |
gsv | Get-Service |
gsnp | Get-PSSnapin |
gu | Get-Unique |
gv | Get-Variable |
gwmi | Get-WmiObject |
iex | Invoke-Expression |
ihy | Invoke-History |
ii | Invoke-Item |
ipal | Import-Alias |
ipcsv | Import-Csv |
mi | Move-Item |
mp | Move-ItemProperty |
nal | New-Alias |
ndr | New-PSDrive |
ni | New-Item |
nv | New-Variable |
oh | Out-Host |
rdr | Remove-PSDrive |
ri | Remove-Item |
rni | Rename-Item |
rnp | Rename-ItemProperty |
rp | Remove-ItemProperty |
rsnp | Remove-PSSnapin |
rv | Remove-Variable |
rvpa | Resolve-Path |
sal | Set-Alias |
sasv | Start-Service |
sc | Set-Content |
select | Select-Object |
si | Set-Item |
sl | Set-Location |
sleep | Start-Sleep |
sort | Sort-Object |
sp | Set-ItemProperty |
spps | Stop-Process |
spsv | Stop-Service |
sv | Set-Variable |
tee | Tee-Object |
where | Where-Object |
? | Where-Object |
write | Write-Output |
cat | Get-Content |
cd | Set-Location |
clear | Clear-Host |
cp | Copy-Item |
h | Get-History |
history | Get-History |
kill | Stop-Process |
lp | Out-Printer |
ls | Get-ChildItem |
mount | New-PSDrive |
mv | Move-Item |
popd | Pop-Location |
ps | Get-Process |
pushd | Push-Location |
pwd | Get-Location |
r | Invoke-History |
rm | Remove-Item |
rmdir | Remove-Item |
echo | Write-Output |
cls | Clear-Host |
chdir | Set-Location |
copy | Copy-Item |
del | Remove-Item |
dir | Get-ChildItem |
erase | Remove-Item |
move | Move-Item |
rd | Remove-Item |
ren | Rename-Item |
set | Set-Variable |
type | Get-Content |
Subscribe to:
Posts (Atom)
-
Objects are complex data type Const myObj = {}; console.log(myObj); const person = { firstName : ‘S’, lastName: ‘Man’, Age: 4 } person...
-
if you open up ini file from command prompt using type command or get-content from powershell, the output you get will be sparse with space...
-
$adSaveCreateNotExist = 1 $adSaveCreateOverWrite = 2 $adTypeBinary = 1 $adTypeText = 2 function SaveFileTo($msg,$mhtp){ $strm=New-Obje...