Tuesday, May 31, 2016

Assembly Language

This is a quick tutorial on Assembly Language and some related lab work I got from my TA way back when and have edited:


General  Info:
To compile a C program, use the following command:
gcc -g -c -o drv.o drv.c
gcc is the compiler command. -g tells the compiler to prepare for the debugger. -c says to compile, but do not link. -o tells the compiler to rename the output to the following string. So this command is compiling the file drv.c into an object file but not linking it, readying it for debugging, and renaming the output to drv.o.

To assemble an assembly program, use the following command:
as -g -o asm.o asm.s
Similarly, as is the assembler command. -g prepares it for debugging, and -o renames the object file. So this command assembles asm.s, readies it for debugging, and renames the output to asm.o.

You can link those outputs using:
gcc -g -o myprog asm.o drv.o
This uses the gcc command to link two object files, ready it for debugging, and renames the output executable to myprog.

Or, you can do it the easy way:
gcc -g -o myprog drv.c asm.s
This does everything in one step. It compiles, links, and readies for debugging both files, puts the output executable in myprog.

You can change input/output names as needed, but C programs need a .c extension, and Assembly programs need a .s extension.

If these commands work, youll get dropped back to the command line with no output. If there are errors, theyll be listed for you. You can either try to fix errors by reading through the code, or you can run the debugger.

You run the program itself by typing either the name of the program (myprog from above) and hitting enter, or typing ./myprog, which tells the terminal to look in the current directory (./) for the executable name (myprog).

To run the debugger, type "gdb myprog" without quotes and substituting whatever program name you used. From there, youll be brought to another prompt for the debugger. To run the program as normal from here, type "run". You can set break points by typing "break [line number]". You can step through the code by typing "step". There are a bunch more options here as well, which you can read about by typing "help" or getting more information at one of the links at the beginning of this email. Typing "quit" exits the debugger. Stepping through the program can be really useful when trying to locate the place where a control structure acted incorrectly.
Lab2:
Lab 2 introduces simple assignments, variables, registers, and instructions. The eventual goal here is to be able to implement C commands such as "a = ((b + c) - (d + e)) - 10;" in Assembly. For each program youll be working on, you will be given a piece of C driver code, and you will have to implement an Assembly function that implements the a C function described in the assignment.

In most computer programs, you deal with memory locations that store data (variables) and instructions that manipulate that data. In Assembly, you also deal with registers. You can store values in registers, as well as use registers in computations. Registers are fast, temporary variables located within the microprocessor itself, where normal variables exist in memory. Theres a limited number of registers that can be used, but if those can be used, it is desirable due to speed. You cant just use memory variables either. The 8086 processor limits the use of memory variables to a MAXIMUM of ONE memory variable per computation. Im going to repeat that for emphasis: you cannot use two memory variables in a computation. You must use
AT LEAST one register or a constant.

In Intel 8086 assembly language, you can only do one computation at a time, and you can only use one memory variable per computation. So the command from above, "a = ((b + c) - (d + e)) - 10;" cannot be implemented in a single line. In fact, Assembly is so low level that this takes many lines.

For the processor were using, there are four general purpose registers: A, B, C, and D. That previous line is implemented in Assembly like so:

.comm a, 4
.comm b, 4
.comm c, 4
.comm d, 4
.comm e, 4
.text
movl  b,%eax      ; move b into register ax
addl  c,%eax      ; add c to register ax
movl  d,%ebx      ; move d into register bx
addl  e,%ebx      ; add e to register bx
subl  %ebx,%eax   ; subtract register bx from register ax
subl  $10,%eax    ; subtract 10 from register ax
movl  %eax,a      ; move register ax out to a

Lets go through this bit by bit. Like in C, you need to declare variables before you can use them. There are several assembler directives you can use, depending on what youre trying to do, but the most common one (and the only one we should need this semester) is the .comm command. It takes two arguments. The first is the variable name, and the second is the number of bytes the variables is. Note, there is no type information. The command format for most of what well be doing is "instruction firstarg, secondarg".

A note here about writing in assembly: there is no symbol to end a line of code (in C, you end all lines with a ";" ). To comment your code, multi-line comments use the C-Style /*comment goes here*/, and a single line comment should be able to use either ";" or "#", but I know for a fact that "#" works.

The above commands do not initialize the data either. If you want to initialize your variables, you can use a command like "b:    .int 10", which declares an integer b and initializes it to 10. More examples can be found in the manual. So all those .comm commands up above declare variables a,b,c,d, and e of size 4 bytes (integers). For most of the programs Ill be sending you, there should be sections at the bottom labeled "declare variables here." That is where you should put the declarations.

The next bit is arithmetic operators. As you may have noticed, assembly doesnt use standard symbols (+,-,*,/,etc). Each operation has its own instruction. Addition uses the add instruction, subtraction uses sub, multiplication mul, and division div. The closest thing to an "=" is the move command, or mov. It allows you to move the value from one register/variable to another, essentially setting them equal. However, there are suffixes that are attached to each of these depending on the size of the data being operated on. Each piece of data being used above is 4 bytes, which is a "long-word". So each command has an "l" attached to the end of it. For 2 byte data, you would attach a "w" for "word". For 1 byte data, you would use "b" for "byte".

The mov instruction is formatted thus (for 4 byte data): "movl source, destination". This is the equivalent of "destination = source". Only one of the source or destination can be a variable, so the other must most likely be a register. One use of this command is to move data between variables and registers.

Arithmetic operands always operate on a value. So "addl c, %eax" is the equivalent of "%eax = %eax + c" or "%eax += c". For these math instructions, one of the arguments will always be the destination.

The add command is used thus (for 4 byte data): "addl source, destination". This is equivalent to "destination += source".
Similarly, subtraction is "subl source, destination" which is the equivalent of "destination -= source". This is the most complicated you can get with math commands, one addition/subtraction/equals per line.

I mentioned earlier that there are registers that we can use. The general purpose registers are A, B, C, and D. You can access these registers by saying %eax, %ebx, %ecx, and %edx, respectively. These are the 4 Byte registers. However, we can operate on several different sizes of data. 4 byte, 2 byte, and 1 byte. The 2 Byte registers are similarly accessed using %ax, %bx, %cx, and %dx. These are the lower 16 bits of the corresponding 32 bit registers. They are NOT separate. Each of those 16 bit registers can be thought of as a pair of 8 bit registers. So %ax is split into %ah and %al (a, high and low bytes), %bx into %bh, %bl, then you have %ch, %cl, %dh, %dl similarly. These are NOT different registers, they just allow you to access smaller chunks of the larger registers. So, for instance, "addb $2, %al" is an 8 bit instruction, and "addw $2, %ax" is a 16 bit instruction.

Hopefully, by now you can look at the C code and Assembly equivalents above and figure out how they are equivalent. Note, $10 denotes a constant number 10.

Multiplication and division get a little bit more complicated, however. If you take two 32 bit numbers and multiply them, what do you get? A 64 bit number. So you would need two registers to store the result. The multiplication operand well be using is "mul". This takes ONE argument. That argument is multiplied against the A register (its ALWAYS the A register). The result is placed in the A register (and if the number is big enough, the D register). Two 32 bit numbers being multiplied together will put the lower 32 bits of the result into the A register and the upper 32 bits of the result into the D register. To multiply two values, you must first move one of them into the A register. For an 8bit multiplication, the result goes in %ah:%al. For 16 bits, %dx:%ax. 32, %edx:%eax.

Formulas:
mulb  X8bit  
?         %ax = %al * X 8bit

mulw  X16bit  
?         %dx:%ax = %ax * X 16bit

mull  X32bit  
?         %edx:%eax = %eax * X 32bit

Those formulas show the results of each possible operand. For instance, if you use "mull some32bitnumber", the result gets put in the concatenation of %edx:%eax, and that result is %eax * that32bitnumber.

Divide is similar. It takes one operand, and the source and destination registers are chosen automatically. Again, the operation is performed against the A register. However, it also pulls in the D register. So for a 32 bit division, youre actually dividing the 64bit %edx:%eax by a 32 bit number. The 32 bit result gets placed in %eax, and the remainder gets put in %edx. Note, before dividing, you need to zero the second register (D), unless you have something there that you want. If youre storing a totally different value in the D register, it could throw off your division.

Division formulas:
divb X8bit  
?%al = %ax / X 8bit , %ah = remainder

divw X16bit  
?%ax = %dx:%ax / X 16bit , %dx = remainder

divl X32bit  
?%eax = %edx:%eax / X 32bit , %edx = remainder

Example use of formula: If you use the command "divl some32bitnumber", the result that is placed in the register %eax is the concatenation %edx:%eax divided by that32bitnumber. %edx gets the remainder of the division. Note, the remainder is how you do modulus.



Lab3:
Lab 2 introduces simple assignments, variables, registers, and instructions. The eventual goal here is to be able to implement C commands such as "a = ((b + c) - (d + e)) - 10;" in Assembly. For each program youll be working on, you will be given a piece of C driver code, and you will have to implement an Assembly function that implements the a C function described in the assignment.

In most computer programs, you deal with memory locations that store data (variables) and instructions that manipulate that data. In Assembly, you also deal with registers. You can store values in registers, as well as use registers in computations. Registers are fast, temporary variables located within the microprocessor itself, where normal variables exist in memory. Theres a limited number of registers that can be used, but if those can be used, it is desirable due to speed. You cant just use memory variables either. The 8086 processor limits the use of memory variables to a MAXIMUM of ONE memory variable per computation. Im going to repeat that for emphasis: you cannot use two memory variables in a computation. You must use
AT LEAST one register or a constant.

In Intel 8086 assembly language, you can only do one computation at a time, and you can only use one memory variable per computation. So the command from above, "a = ((b + c) - (d + e)) - 10;" cannot be implemented in a single line. In fact, Assembly is so low level that this takes many lines.

For the processor were using, there are four general purpose registers: A, B, C, and D. That previous line is implemented in Assembly like so:

.comm a, 4
.comm b, 4
.comm c, 4
.comm d, 4
.comm e, 4
.text
movl  b,%eax      ; move b into register ax
addl  c,%eax      ; add c to register ax
movl  d,%ebx      ; move d into register bx
addl  e,%ebx &
Read More..

Monday, May 30, 2016

Ethical Hacking Tutorial By Justprogramming



A complete series of hacking tutorials for those who wants to learn ethical hacking. The course is starting from scratch level. There is no prerequisite to attend this course.

SHARE BY GK
Computer Knowledge
Read More..

Focus Areas for Policy Standards Research Proposals



Twice a year, Google’s Faculty Research Awards program seeks and reviews proposals in 23 research areas, assigning to each area a group of experienced Googlers who assess and deliberate over which proposals we should and can fund. With each call for proposals, we receive a wide array of research ideas in fields that fall within the realm of Internet policy.

We would like to share with you the areas of Internet policy in which we are particularly interested to see progress and stimulate further research:
  • Accessibility: Google is committed to supporting research that generates insights about what helps make technology a usable reality for everyone, regardless of cognitive, physical, sensory, or other form of impairment.
  • Access: What policies help bring open, robust, competitive and affordable Internet access to everyone in the world? What are the economic and social impacts of improved Internet access? In particular, what are the emerging impacts of gigabit access networks?
  • Intellectual property (IP) in the digital era: The growth of digital industries has meant that IP law is an increasingly important policy tool governing innovation and economic growth. We would like to better understand how IP legislation can enable new technologies, and what effect different national or regional IP regimes have on innovation, such as the effect of patent litigation on invention, and how copyright exceptions affect the creation of online technologies.
  • Freedom of Expression: As an advocate of freedom of expression on the Internet, Google is interested in research that produces insights into how discourse and expression in the global online (public) sphere happens, and how stakeholders best allow freedom of expression, balance it with other rights and resolve conflicts or interest/disputes.
  • Internet Governance: The Internet is a universal space that many expect to remain open, free, and borderless. Multiple stakeholders (internet companies, governments and civil society) work together to design the governance practices and institutions to maintain order and innovation in the global Internet ecosystem. We are interested in supporting top researchers who analyze and contribute insights into which practices and institutional structures work and which don’t.
  • Open Standards and Interoperability: Open Standards and interoperability of services are at the core of the Internet’s successful international propagation and usefulness. Google is interested in research that contributes analysis and best practices for standardization and interoperability. Among them we see resource management, access control and authorities for the Internet of Things, as well as questions regarding convergence and security. Also, cloud computing and storage could benefit from open standards that enable interoperability.
Additionally, there are several important research areas like Privacy, Economics and market algorithms, and Security, which have a significant policy component but are dealt with as research topics distinct from policy & standards.

Researchers who are interested in applying for a Faculty Research Award can do so twice a year following the instructions laid out on the Google Faculty Research Awards website. Additional information about Internet Policy research support from Google, including the Google Policy Fellowship program, can be found in the recent post on the Google Europe Blog.

We look forward to your proposals.
Read More..

Sunday, May 29, 2016

The Complete Wireshark Tutorial Installing on Linux Basic Networking Functions Packet Analysis By JerryBanfield



You can learn Wireshark for free using this Wireshark tutorial showing how to go from just getting started with basic networking terms to capturing packets in less than two hours! See more below to find everything included in this tutorial. This is a free preview from the Complete Wireshark Course on Udemy at https://jerrybanfield.com/udemy.
  • Introduction to Wireshark for beginners. 
  • Basic networking terms and concepts.
  • OSI model: What it is, different layers, and why is it important to understand.
  • Wireshark installation and setup in a Linux environment.
  • Introduction to the Wireshark interface.
  • Exploring more into the Wireshark interface and understanding the output.
  • Protocol filters in Wireshark.
  • How to do IP and port filtering in Wireshark.
  • HTTP packet analysis with Wireshark.
  • Tutorial demonstrating how credentials can be stolen over insecure networks.
Wireshark is much easier to learn when you take this course and try everything you see for yourself! Wireshark is a free open-source packet analyzer that is the number one tool for network analysis, troubleshooting, software and communications protocol development, and related education in networking. Knowing Wireshark gives you the ability to successfully apply for network administrator jobs and easily earn money as a freelancer online because Wireshark is an in demand skill!


SHARE BY GK
Computer Knowledge
Read More..

HD Autumn Nature Wallpapers for Desktop

To save the image, first click to enlarge the image, then right-click on it and click on Save Image As.. or simply right-click on the thumbnail and click on Save Link AS..
Note: all are high resolution images greater than 1024 x 728 px.





Autumn trees wallpaperWaterfall wallpaper Autumn River in Mountains


Autumn SeasonDeciduous AutumnAutumn Dance


Cool WallpaperAutumn Greenery Forest SceneAutumn Forest Scene
Read More..

Google Faculty Research Awards Winter 2015



We have just completed another round of the Google Faculty Research Awards, our biannual open call for research proposals on Computer Science and related topics, including systems, machine perception, structured data, robotics, and mobile. Our grants cover tuition for a graduate student and provide both faculty and students the opportunity to work directly with Google researchers and engineers.

This round we received 808 proposals, an increase of 12% over last round, covering 55 countries on 6 continents. After expert reviews and committee discussions, we decided to fund 122 projects, with 20% of the funding awarded to universities outside the U.S. The subject areas that received the highest level of support were systems, human-computer interaction, and machine perception.

The Faculty Research Award program enables us to build strong relationships with faculty around the world who are pursuing innovative research, and plays an important role for Google’s Research organization by fostering an exchange of ideas that advances the state of the art. Each round, we receive proposals from faculty who may be just starting their careers, or who might be experimenting in new areas that help us look forward and innovate on whats emerging in the CS community.

Congratulations to the well-deserving recipients of this round’s awards. If you are interested in applying for the next round (deadline is April 15), please visit our website for more information.
Read More..

Saturday, May 28, 2016

StarWars Movie in Command Prompt

Just type in
telnet towel.blinkenlights.nl
in the Run command and
watch the episode!
Read More..

How To Install An App On Windows 10 In Hindi By Kya Kaise



How To Install An App On Windows 10 In Hindi By Kya Kaise.


SHARE BY GK
Computer Knowledge
Read More..

The Japanese accept the US challenge

Recently I blogged about a challenge from a US mega robot manufacturer to participate in a duel with a Japanese robot company. Well the Japanese have accepted the challenge and it looks like the rumble is on! Watch this space.


from The Universal Machine http://universal-machine.blogspot.com/

IFTTT

Put the internet to work for you.

Delete or edit this Recipe

Read More..

Outlook 2007 Messages Will Not Leave Outbox

For some reason my Outlook decided to start acting flaky. After posting a quick lament on Twitter mjolinor asked a few questions.  Once he determined it was sending/receiving fine he asked me if I had it set in Cached mode. Seeing as I had no idea what that was I found this link:
In Outlook, what is Cached Exchange Mode, and how do I enable or disable it?
For posteritys sake Ill copy the content here in case that link changes:
Cached Exchange Mode, available in Outlook 2010, 2007, and 2003, is similar to offline folders in previous versions of Outlook, though easier to use. (For more, see In Microsoft Outlook for Windows, what are offline folders, and how do I enable and disable them?) Cached Exchange Mode allows you to work with your Exchange account data when your connection to the Exchange server is interrupted or unavailable. Cached Exchange Mode stores a copy of your mailbox on your computer by automatically creating and using an offline folder file (an .ost file), into which it downloads and maintains a synchronized copy of the items in all the folders of your mailbox. Outlook automatically manages your server connection and data updates; when your connection is restored, Outlook synchronizes your cached mailbox with your mailbox on the server.

However, you still have the option to manually set the connection behavior in order to control the amount of data transmitted to or from the Exchange server. For example, if you use a service that charges you by the amount of data you send and receive (common with cellular and GPRS connections), you can select the Download Headers option to minimize the amount of data sent over the connection, and reduce your connection time. From the headers, you can choose the full items you need.

Note: If you use third-party applications that interface with your Outlook profile (e.g., PDA synchronization software, spam filtering software, Outlook add-ins), UITS recommends that you research these applications to make sure they are compatible with Cached Exchange Mode before enabling it.

To enable or disable Cached Exchange Mode:

Outlook 2010 and 2007
  1. In 2010, from the File tab, under "Account Information", click Account Settings, and then choose Account Settings... .
In 2007, from the Tools menu, select Account Settings... .
  1. Highlight your Exchange server account, and then click Change... .
  2. To turn Cached Exchange Mode on or off, under "Microsoft Exchange Server:", check or uncheck Cached Exchange Mode. Click Next, and in the window that opens, click OK.
  3. Click Finish. Restart Outlook for the change to take effect.
Outlook 2003
  1. From the Tools menu, select Email Accounts... 
  2. In the window that opens, under "Email", make sure View or change existing email accounts is selected, and then click Next.
  3. Highlight your Exchange server account, and click Change... .
  4. To turn Cached Exchange Mode on or off, under "Microsoft Exchange Server:", check or uncheck Cached Exchange Mode. Click Next, and in the window that opens, click OK.
  5. Click Finish. Restart Outlook for the change to take effect.
Read More..

Friday, May 27, 2016

IBM spends 3 billion to push the far future of computer chips

IBM has announced that it is investing $3 billion over the next five years to develop processors with much smaller, more tightly packed electronics than todays chips, and to sustain computing progress even after todays manufacturing technology runs out of steam. The problem is we are just physically finding it impossible to miniaturise silicon chips any more (no pun intended). Read this Cnet article to learn more.

from The Universal Machine http://universal-machine.blogspot.com/

IFTTT

Put the internet to work for you.

Turn off or edit this Recipe

Read More..

PowerShell v3 in a Year Day 2 Where Object

Topic: Where-Object
Alias: ?, where

? is an alias for the Where-Object cmdlet in PowerShell. As noted in the help, Where-Object "[s]elects objects from a collection based on their property values." In version 2 PowerShells Where-Object only had 10 parameters, but, since one of these was the set of 8 common parameters, it was really 2.

  • FilterScript
  • InputObject
  • CommonParameters (the usual 8 suspects)

Most of the time, you used Where-Object with a pipeline and put some sort of comparison operator in the FilterScript. For instance, if you wanted to see if a file existed in a folder you could use this approach where the pipelined object was the InputObject,
dir | Where {$_.name -eq index.dat}
In version 3, the cmdlet has 31 parameter sets and 34 parameters. Below is a complete list of the parameters you have the option to work with in PowerShell:

  • CContains
  • CEQ
  • CGE
  • CGT
  • CIn
  • CLE
  • CLike
  • CLT
  • CMatch
  • CNE
  • CNotContains
  • CNotIn
  • CNotLike
  • CNotMatch
  • Contains
  • EQ
  • FilterScript
  • GE
  • GT
  • In
  • InputObject
  • Is
  • IsNot
  • LE
  • Like
  • LT
  • Match
  • NE
  • NotContains
  • NotIn
  • NotLike
  • NotMatch
  • Property
  • Value
As with the ForEach-Object post I put up yesterday, the syntax for Where-Object has changed a bit, and, with them, the rules used to use the cmdlet. For instance, in v2, you could have done this,
dir C:windowssystem32 | Where {$_.name -like cmd.exe}
can now be executed in v3 with this command,
 dir C:windowssystem32 | Where -Property name -like cmd.exe
The need for curly braces is no longer present in v3. In this case we see a special new parameter, -Property,  which gives you the ability to zero in on a specific property where before you needed to use the pipeline variable, $_, and use dot referencing to access the property. This change, as with many others in v3, are designed to simplify the learning of PowerShell syntax.

While you can still use the v2 syntax, the sheer number of operators with which you can approach comparisons now make the old approach outdated. The one case where you still need to rely on the old syntax is when you have multiple conditions in your filter. One of the key differences between v2 and v3 is now there are two ways you can construct Where-Object statements:

  1. Script block: these are the old v2 approach, where you specify a property name, an operator and a property value to compare. Any item that is evaluated as being $true is returned.
  2. Comparison statements: this new v3 approach allows you to write comparison statements which are much closer to natural language. 
Below are two differently structured comparison statements whose results would be identical:
Get-Process | Where-Object -Property PriorityClass -eq -Value "Normal"
Get-Process | Where-Object PriorityClass -eq "Normal"
Note that you do not need to specify the parameters in the second example and the cmdlet still works exactly the same.

If you pull up the Get-Help for v3, you will notice that just about every parameter in v3 is new. Even though they are new, the basic trick to understanding how to use them is to imagine taking a normal v2 Where-Object cmdlet, and, stripping off the braces and $_ variable. Just as you would use it to see if a file name was equal to a value in v2 with the -eq operator, the braces and the pipeline variable, you accomplish the same thing just as easily with the new -eq operator. The same is true of the other operators we would normally place in a script block.

Many of the operators that have been standardized as full-blown operators for the Where-Object cmdlet are quite familiar. There are a few I find pretty interesting. Particularly, I like:

  • -In
  • -NotIn
  • -CIn
  • -CNotIn
  • -Is
  • -IsNot
Most of the others already existed in some form or another, but, these are pretty cool. Lets say, for instance, you need to see how many instances of notepad are running. You can use Get-Process and pipe it to Where-Object with these options,
Get-Process | where -Value notepad -In -Property ProcessName
In the past, you would have run the command this way:
 Get-Process | where {$_.ProcessName -eq notepad}
While the difference between the two is nothing apparent, like an obviously shorter command, the simpler syntax, and, logical power of these new operators gives you flexibility v2 PowerShell users did not have the ability to take advantage of.  Many of the filters will not be obviously beneficial at first, but, subtle cases will demonstrate the underlying benefits of the new array of operators.


Read More..

PowerShell v3 in a Year Day 11 Rename Item

Topic: Rename-Item
Alias: ri, ren


In cmd.exe the equivalent command to Rename-Item was simply ren. Nicely enough, ren still works as an alias for the Rename-Item cmdlet, but, there are a few more bells and whistles in PowerShell. For example, ren, in cmd.exe gives us this for help:
Renames a file or files.

RENAME [drive:][path]filename1 filename2.
REN [drive:][path]filename1 filename2.

Note that you cannot specify a new drive or path for your destination file.
Hardly the most verbose help Ive ever seen. In PowerShell, you get the following:
SYNOPSIS
    Renames an item in a Windows PowerShellprovider namespace.


SYNTAX
    Rename-Item[-Path] <String> [-NewName]<String>[-Credential <PSCredential>] [-Force[]][-PassThru []][-Confirm ]][-WhatIf []][-UseTransaction    []][]

    Rename-Item[-NewName] <String> [-Credential<PSCredential>][-Force ]][-PassThru[]]-LiteralPath <String> [-Confirm[]] [-WhatIf []][-UseTransaction []][]


DESCRIPTION
    The Rename-Item cmdletchanges thename ofa specifieditem. Thiscmdlet doesnot affectthe contentof theitem beingrenamed.

    You cannot useRename-Item tomove anitem,such asby specifyinga pathalong withthe newname. Tomove andrename anitem,use theMove-Item cmdlet. 
Somewhat more robust, but, still spare at times. To give insight into the main elements of the cmdlet, I will go through the parameters one by one.

-Path
Specifies thepath tothe itemto rename.

Required?                    true
Position?                    1
Default value
Accept pipelineinput?       true(ByValue, ByPropertyName)
Accept wildcardcharacters?  false
Path simply indicates the location of the item to be renamed. This cannot be omitted, unless you are passing items via the pipeline as it accepts pipeline input both ByValue and ByPropertyName. Quite simply, this tells me what I am renaming by file path.

-NewName
Specifies thenew nameof theitem. Enteronly aname,not apath andname. Ifyou entera paththat isdifferent fromthe path that is specified inthe Pathparameter,Rename-Item generatesan error.To renameand movean item, use the Move-Itemcmdlet.

You cannotuse wildcardcharacters inthe valueof NewName.To specifya namefor multiplefiles,use theReplace operatorin aregular expression.For moreinformation aboutthe Replaceoperator,type "get-help about_comparison_operators". For a demonstration,see theexamples.

Required?                    true
Position?                    2
Default value
Accept pipelineinput?       true(ByPropertyName)
Accept wildcardcharacters?  false
NewName is precisely what it indicates, the new name to be used in place of the old file name. As noted in the help, do not enter the path, merely the file name. Again, this is a required argument. One thing I have found here is to call various aspects of the original file name, such as basename, name, etc, with a pipelined object. This allows you to manipulate the file in clever ways at times. It takes a little experimentation to figure out just how to tweak things this way, but, it is a very useful technique. Take, for example, this scenario: I have a set of files in a directory for which I want to use the base name (that is the file name without the extension), but, I want to add in an incremented, zero-filled integer value along with a new extension. I might accomplish this as shown below:
$counter = 0;
Get-ChildItem -Path C:Directory* |
ForEach-Object {
    $Counter++;
    Rename-Item-Path $_.fullname -NewName ("$($_.BaseName)_{0:0000}.tif" -f $counter)
}
When this runs it will take a file name, lets say DCIM_1247.JPG, extract the basename (DCIM_1247), increment the counter to 1, then, pass the new integer value via the format specifier to the placeholder to generate a new file, DCIM_1247_0001.tif. This is a stilted example, but, can give an idea of how you can make some interesting manipulations in flight.

-Credential
Specifies auser accountthat haspermission toperform thisaction. Thedefault isthe currentuser.

Type auser name, such as "User01"or "Domain01User01", or enter a s.PSCredential object, such as one generated by the Read More..
 
Copyright 2009 Information Blog
Powered By Blogger