Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - ren filename with time help

Reply
 
Old 11-05-2008   #1 (permalink)
Joe


 
 

ren filename with time help

Hi Gang,

I'm driving myself crazy with this problem! Goal, write a logfile
with current time as the filename...

examples being:

$time1=get-date -UFormat "%H%M-%d%m%y"
get-ExecutionPolicy >> $time1.log
///completes but no file is created///

PS C:\temp> $time1
1936-051108

///ok let's try it like this///
PS C:\temp> ren c:\temp\test.log -newname $time1
///this works but no file extension???///

PS C:\temp> ren c:\temp\test.log -newname $time1.log
Rename-Item : Cannot bind argument to parameter 'NewName' because it
is null.
At line:1 char:30
+ ren c:\temp\test.log -newname <<<< $time1.log


thanks in advance!


My System SpecsSystem Spec
Old 11-05-2008   #2 (permalink)
Jeff


 
 

Re: ren filename with time help

On Nov 6, 11:20*am, Joe <joedon...@xxxxxx> wrote:
Quote:

> Hi Gang,
>
> I'm driving myself crazy with this problem! *Goal, write a logfile
> with current time as the filename...
>
> examples being:
>
> $time1=get-date -UFormat "%H%M-%d%m%y"
> get-ExecutionPolicy >> $time1.log
> ///completes but no file is created///
>
> PS C:\temp> $time1
> 1936-051108
>
> ///ok let's try it like this///
> PS C:\temp> ren c:\temp\test.log -newname $time1
> ///this works but no file extension???///
>
> PS C:\temp> ren c:\temp\test.log -newname $time1.log
> Rename-Item : Cannot bind argument to parameter 'NewName' because it
> is null.
> At line:1 char:30
> + ren c:\temp\test.log -newname <<<< *$time1.log
>
> thanks in advance!
Try this:

Get-ExecutionPolicy > "$( Get-Date -UFormat '%H%M-%d%m%y' ).log"

When you put .log on the end of a variable name, PowerShell thinks it
is a property named "log", and will try to evaluate it. Because it
evaluates to null, no file is created.

Jeff
My System SpecsSystem Spec
Old 11-06-2008   #3 (permalink)
Joe


 
 

Re: ren filename with time help

On Nov 6, 12:37*pm, Jeff <jeff.hill...@xxxxxx> wrote:
Quote:

> On Nov 6, 11:20*am, Joe <joedon...@xxxxxx> wrote:
>
>
>
Quote:

> > Hi Gang,
>
Quote:

> > I'm driving myself crazy with this problem! *Goal, write a logfile
> > with current time as the filename...
>
Quote:

> > examples being:
>
Quote:

> > $time1=get-date -UFormat "%H%M-%d%m%y"
> > get-ExecutionPolicy >> $time1.log
> > ///completes but no file is created///
>
Quote:

> > PS C:\temp> $time1
> > 1936-051108
>
Quote:

> > ///ok let's try it like this///
> > PS C:\temp> ren c:\temp\test.log -newname $time1
> > ///this works but no file extension???///
>
Quote:

> > PS C:\temp> ren c:\temp\test.log -newname $time1.log
> > Rename-Item : Cannot bind argument to parameter 'NewName' because it
> > is null.
> > At line:1 char:30
> > + ren c:\temp\test.log -newname <<<< *$time1.log
>
Quote:

> > thanks in advance!
>
> Try this:
>
> Get-ExecutionPolicy > "$( Get-Date -UFormat '%H%M-%d%m%y' ).log"
>
> When you put .log on the end of a variable name, PowerShell thinks it
> is a property named "log", and will try to evaluate it. *Because it
> evaluates to null, no file is created.
>
> Jeff
it's always something simple, thanks!
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: How can I search for a ( in the filename only? Vista General
about 8.3 filename Vista General
Add Date and time to filename PowerShell
Get-Acl for filename containing [ and ] PowerShell
What is the RC2 filename please? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46