Solved

What is the powershell equivalent to linux command "touch" ?

Posted on 2013-10-22
5
3,542 Views
Last Modified: 2013-10-27
Hi People,

Can anyone please suggest me what is the correct powershell command to "touch" a file like in Linux environment ?

Copy-Item .\somefile.xml \\.\nul\

Open in new window


does that code performs the same thing ?
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 35

Assisted Solution

by:Seth Simmons
Seth Simmons earned 250 total points
ID: 39592824
use New-Item

http://technet.microsoft.com/en-us/library/ee176914.aspx

PS C:\Users\seth> New-Item foo.txt -type file


    Directory: C:\Users\seth


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        10/22/2013   7:31 PM          0 foo.txt

Open in new window

0
 
LVL 8

Author Comment

by:Senior IT System Engineer
ID: 39593114
ah ok, so what does the Copy-Item .\somefile.xml \\.\nul\ does then ?
0
 
LVL 40

Assisted Solution

by:footech
footech earned 250 total points
ID: 39593306
I don't see how New-Item would work, it would just create a new file.
I also don't see how the Copy-Item command would work (and in testing it doesn't).
Since the touch command just updates the Last Modified timestamp on a file, here's an equivalent.
(Get-Item somefile.txt).LastWriteTime = Get-Date

Open in new window

0
 
LVL 35

Assisted Solution

by:Seth Simmons
Seth Simmons earned 250 total points
ID: 39594569
if you go on a linux machine and touch foo
it will create a file called foo; same as New-Item
0
 
LVL 40

Accepted Solution

by:
footech earned 250 total points
ID: 39594664
You're right, I forgot about that functionality of touch.  So I suppose that the answer depends on what functionality of the utility needs to duplicated.  Otherwise, a function could be created to handle multiple functions depending on conditions.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question