获取脚本当前所在路径:

$CurrentPath = $MyInvocation.MyCommand.Path.substring(0,$MyInvocation.MyCommand.Path.LastIndexOf('\')+1)
$today = Get-Date -UFormat "%Y%m%d"
$LogFilePath = $CurrentPath+"Result_$today.txt"

get-process |out-file $LogFilePath -Append

$Currentpath     = Split-Path -parent $MyInvocation.MyCommand.Definition

格式化日期:

$now = get-date -format 'yyyyMMddHHmm'
$dpunmountcmd_ScriptName = "DPUnmount_script_" + $now + ".txt"

$yes = (get-date).adddays(-1)
get-date -date $yes -uformat "%Y/%M/%d" 输出: 2014/06/23

$yes.tostring("yyyy\/MM\/dd")  输出: 2014/06/23

Get-Date使用Format参数考取年、月、日、时、分、秒

yyyy    年
M    月
d    日
h    小时(12小时制)
H    小时(24小时制)
m    分钟
s    秒

Get-Date -UFormat "%Y/%m/%d"   :2014/04/18

get-date -uformat %R  :11:07

==============================

Get-Date -UFormat %<value>

For example,

Get-Date -UFormat %d

Date-Time:

Date and time - full

(default) (Friday, June 16, 2006 10:31:27 AM)

c Date and time - abbreviated (Fri Jun 16 10:31:27 2006)

Date:

D Date in mm/dd/yy format (06/14/06)

x Date in standard format for locale (09/12/07 for English-US)

Year:

C Century (20 for 2006)

Y Year in 4-digit format (2006)

y Year in 2-digit format (06)

G Same as 'Y'

g Same as 'y'

Month:

b Month name - abbreviated (Jan)

B Month name - full (January)

h Same as 'b'

m Month number (06)

Week:

W Week of the year (00-52)

V Week of the year (01-53)

U Same as 'W'

Day:

a Day of the week - abbreviated name (Mon)

A Day of the week - full name (Monday)

u Day of the week - number (Monday = 1)

d Day of the month - 2 digits (05)

e Day of the month - digit preceded by a space ( 5)

j Day of the year - (1-366)

w Same as 'u'

Time:

p AM or PM

r Time in 12-hour format (09:15:36 AM)

R Time in 24-hour format - no seconds (17:45)

T Time in 24 hour format (17:45:52)

X Same as 'T'

Z Time zone offset from Universal Time Coordinate (UTC) (-07)

Hour:

H Hour in 24-hour format (17)

I Hour in 12 hour format (05)

k Same as 'H'

l Same as 'I' (Upper-case I = Lower-case L)

Minutes & Seconds:

M Minutes (35)

S Seconds (05)

s Seconds elapsed since January 1, 1970 00:00:00 (1150451174.95705)

Special Characters:

n newline character (\n)

t Tab character (\t)

详细参考:http://www.cnblogs.com/dreamer-fish/p/3805726.html

From:http://technet.microsoft.com/zh-cn/library/hh849887.aspx

Current_Path 获取脚本所在路径(当前路径),取当前时间做文件名(uformat)的更多相关文章

  1. Delphi获取文件名、文件名不带扩展名、文件名的方法;delphi 获取文件所在路径

    取文件名 ExtractFileName(FileName); 取文件扩展名: ExtractFileExt(filename); 取文件名,不带扩展名: 方法一:   Function Extrac ...

  2. bat(续五)-获取批处理文件所在路径

    获取批处理文件所在路径        在开发时,经常需要使用批处理运行一些程序,java程序 犹其是这样,往往需要运行时根路径.Hardcode一个路径总是令自己觉得不自在,例如一个java程序从一台 ...

  3. C#: 获取执行程序所在路径和启动资源管理器

    一. 获取执行程序所在路径 1.获取和设置当前目录的完全限定路径. string str = System.Environment.CurrentDirectory;  //获取的是主程序目录,线程启 ...

  4. delphi根据进程PID获取程序所在路径的函数(用OpenProcess取得句柄,用GetModuleFileNameEx取得程序名)

    uses psapi; {根据进程PID获取程序所在路径的函数}function GetProcessExePath(PID: Cardinal): string;varpHandle: THandl ...

  5. Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法

    Qt 程序获取程序所在路径.用户目录路径.临时文件夹等特殊路径的方法 经常我们的程序中需要访问一些特殊的路径,比如程序所在的路径.用户目录路径.临时文件夹等.在 Qt 中实现这几个功能所用的方法虽然都 ...

  6. Application.StartupPath获取执行文件路径substring()取特定长度字符串取得根目录

    Application.StartupPath获取执行文件路径substring()取特定长度字符串取得根目录 2012-07-20 10:48 257人阅读 评论(0) 收藏 举报 path usi ...

  7. dotnet 获取程序所在路径的方法

    在 dotnet 有很多方法可以获取当前程序所在的路径,但是这些方法获取到的路径有一点不相同,特别是在工作路径不是当前的程序所在的路径的时候 通过下面几个方法都可以拿到程序所在的文件夹或程序文件 Ap ...

  8. python 获取脚本所在目录

    平时写python经常会想获得脚本所在的目录,例如有个文件跟脚本文件放在一个相对的目录位置,那就可以通过脚本文件的目录找到对应的文件,即使以后脚本文件移到其他地方,脚本也基本不需要改动(相对于写死目录 ...

  9. 批处理文件中获取当前所在路径的几种方法,以及写文件到txt

    @echo off setlocal EnableDelayedExpansion echo 当前正在运行的批处理文件所在路径:!cd! pause @echo off echo 当前目录是:%cd% ...

随机推荐

  1. ERROR 1064 (42000): You have an error in your SQL syntax;

    出现: ERROR 1064 (42000): You have an error in your SQL syntax; 1.SQL语句拼写错误. 具体很简单.慢慢查看 2.使用到了SQL关键字. ...

  2. html5与html4区别

    1.声明方法简化,doctype.meta 2.有些元素可以省略标记,body.tbody... 3.新增语义化标签,<section><article>...<arti ...

  3. java.lang.IllegalStateException: Unknown Priority XXXX 的解决方法

    异常信息: java.lang.IllegalStateException: Unknown Priority SYS_ERR_SMS at org.apache.log4j.Category.pri ...

  4. Scope of a Declaration

    6.3. Scope of a Declaration The scope of a declaration of a member m declared in or inherited by an ...

  5. Django时间与时区设置问题

    在Django的配置文件settings.py中,有两个配置参数是跟时间与时区有关的,分别是TIME_ZONE和USE_TZ 如果USE_TZ设置为True时,Django会使用系统默认设置的时区,即 ...

  6. jQuery插件开发之datalist

    HTML5中定义了一种input框很好看的下拉列表--datalist,然而目前它的支持性并不好(万恶的IE,好在你要渐渐退役了...).于是最近更据需求写了一个小型datalist插件,兼容到IE8 ...

  7. module使用和设置

    Modules environmentDescription This is a system that allows you to easily change between different v ...

  8. 汇编语言、与C语言、实现--汉诺塔--

    题意描述:   用汇编语言实现汉诺塔.只需要显示移盘次序,不必显示所移盘的大小,例如: X>Z,X>Y,Z>Y,X>Z,..... (n阶Hanoi塔问题)假设有三个分别命名为 ...

  9. ubuntu上安装R的时候遇到的问题总结

    首先感谢这两篇博客的指导,第一篇是关于报错的总结,第二篇是第一篇中没有提到的错误,也就是我在安装的时候出现的错误. 1.下载R包 (去官网选择一个离你最近的镜像网址,我的是清华提供的镜像下载速度比较快 ...

  10. [转]Sql Server 分页存储过程

    本文转自: 版权声明:作者:jiankunking 出处:http://blog.csdn.net/jiankunking  本文版权归作者和CSDN共有,欢迎转载,但未经作者同意必须保留此段声明,且 ...