获取脚本当前所在路径:

$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. sqlplus 调试存储过程

    SQLPLUS里测试带返回参数的存储过程过程名p_test入参 aa varchar2出参 bb sys_refcursor 在SQLPLUS里如何将sys_refcursor 这个结果集获取出来呢 ...

  2. 【LeetCode题解】94_二叉树的中序遍历

    目录 [LeetCode题解]94_二叉树的中序遍历 描述 方法一:递归 Java 代码 Python代码 方法二:非递归 Java 代码 Python 代码 [LeetCode题解]94_二叉树的中 ...

  3. android studio的jni和so

    1. android studio自己添加代码生成so 代码地址:https://github.com/maogefff/Android-Test-Sample/tree/master/MyJni 参 ...

  4. Vue2.0项目实战语法

    一.安装配置依赖 1) vue init webpack-simple 项目名称 2) cnpm install 3 )  npm run dev 4 )  cnpm install vuex vue ...

  5. 来一波Linux中查看cpu、磁盘、内存、网络的命令

    转载请注明出处. 如果想远程管理服务器就有远程管理卡,比如Dell idRAC,HP ILO,IBM IMM 查看硬件的温度/风扇转速,电脑有撸大师,服务器就有ipmitool.使用ipmitool实 ...

  6. del

    Before writing it I spent a fair amount of time on reviewing our chat-log. How silly. asljdfajsodfss ...

  7. HDU 2546(01背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=2546 http://blog.csdn.net/xujinsmile/article/details/79694 ...

  8. SQL语句的拼凑

    StringBuilder sql = new StringBuilder("SELECT * FROM t_customer WHERE 1=1"); /* * 2. 判断条件, ...

  9. jquery 提示语淡入效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. react生命周期es6

    基本函数有 import React from 'react' export default class MyClass extends React.Component { constructor(p ...