簡體   English   中英

在PowerShell中合並兩個命令

[英]Combine Two Commands in PowerShell

我知道必須有一個簡單的答案,但是如何同時運行兩個命令? 我可以運行一行來創建新目錄並命名,然后將項目從一個文件夾復制到另一個文件夾。 但是,如何創建文件夾並將文件復制到該創建的文件夾中?

    #Creates new directory and names it current date and time.
    New-Item C:\ -type directory -Name ("$(Get-Date -f ddMMyyyy_hhmm)")

    #Copies Data from one directory to another, works good.
    Copy-Item C:\test\* C:\test2

謝謝你的幫助。

您可以將New-Item返回的對象的FullName屬性用作另一個命令的目標。

Copy-Item C:\somefolder\* -Destination (New-Item -type Directory -name (Get-Date -f ddMMyyyy_hhmmss)).FullName

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM