Command for Robocopy to log created date - powershell

I'm using Robocopy's log feature to get file information regardless of folder depth (from Learn-PowerShell).
I was able to get a file's timestamp using /TS option of Robocopy, but this timestamp is modified date of the file.
I also need to log the created date.
So how can I log created date of file?
And another one, how to log Modified date and Created date of folder too, using Robocopy?

if you can find a computer with PowerShell v5 you can install a module called PSAlphaFS .
Install-Module PSAlphaFS
copy the module to your system running powershell 4 and import it.
Import-module PSAlphaFS
then run the following command which is similar to get-childitem but without the 260 char limitation.
Get-LongChildItem -Path C:\temp -Recurse |
Select-Object Name,FullName,CreationTime,LastWriteTime

Related

Powershell Script for automatic execution of an .exe file, located in different directories, on the same base directory

I am trying to execute an .exe executable file (let' say it is called myfile.exe) under the argument (argument.fst) . Both files have the same name for each execution, but are located in different subfolders in the same parent directory.
My objective is to create a for-loop, in which, I will pinpoint the paths to both files (14 groups in total, so 14 loops) and then Windows Powershell will execute those. My goal is to automate my simulations, ran by the .exe files+arguments, thus saving time.
Is my thought possible to be implemented on Windows Powershell?
Thank you very much,
Ioannis Voultsos.
If you want to automate the process, you may store your command,args in csv file (i.e. commands.csv):
command;arguments
myapp.exe;c:/
myapp.exe;h:/
then load it and execute using &:
$csv=(import-csv commands.csv -delimiter ';')
$csv|foreach{ &$_.command $.arguments }
Beware of executing commands from strings, coming from untrusted sources though.
Try out this sample code on the parent folder
Get-ChildItem | Where-Object {($_.psiscontainer)} | ForEach-Object { cd $_.FullName; & ".\SampleApp.exe args0 args1"; cd.. }
it will go into each directory and execute .exe in each folder with arguments.

PowerShell - can´t find long path but file exists

I have an issue while trying to run a PowerShell script.
When i try to obtain a file content (ex. Get-Content ".\d\e\file.xml") using a script a few directories bellow this .xml it works.
But, if i run this script from a different directory to get the file content (ex. c:\users\x\desktop), it will not be able to read it. I have tried Set-Location -Path "C:\a\b\c\ so it can get by relative path.
This is the error that I´m having:
Cannot find path 'C:\a\b\c\d\e\file.xml' because it does not exist. (path has 263 characters, too long)
Powershell Version : 5.1.18362.628

What is PowerShell command output default location?

Following this official Azure tutorial. When I run the following PowerShell command (mentioned in Create a project ZIP file section of the tutorial), it runs successfully but I don't know where the zip file created by the command is located.
Compress-Archive -Path * -DestinationPath myAppFiles.zip
I don't see the file in following location either: C:\Windows\System32\WindowsPowerShell\v1.0. What is the default output location for PS command?
The default output location in this case is your current working directory. Running that cmdlet as posted will copy everything in the current directory into $CurrentDirectory\myAppfiles.zip
Note that as you're not specifying the actual path, you'll want to Set-Location to the actual location of the items you're trying to compress. When you do that, the .zip file will end up in that directory.

Chef doesn't call the second line of the PS script

I'm using Chef Kitchen to do a POC. We have a PowerShell script which goes to a network path, sorts the build based on date [Install shield installer], copies to the VM in a folder.
This script works correctly when I run inside the VM manually using Power Shell. When I run using Chef Kitchen I don't get any error, the recipe is run but only the first line.I can see the folder called Build created in the VM.
I did an experiment and added a second line to create another folder, it worked correctly. So the issue is the logic I used to copy and paste the build doesn't seem to work with Chef.
The first line creates a new folder, the second and third sets the source and destination path. The fourth line copies the build from the network path [Sort by date to get the latest] to the VM. And the last one is to rename.
And also is there an efficient way to copy a file from a network path [Sorting by date] to a VM using Chef?
powershell_script 'CopyBuild' do
code <<-EOH
New-Item -ItemType directory -Path C:\Build
$source = gci \\BuildPath\Build | ? { $_.PSIsContainer } | sort CreationTime -Desc | select -f 1
$destination = "C:\Build"
Copy-Item "\\BuildPath\Build\$source\*" $destination
Get-ChildItem $destination -r -i "*app1*.exe" | Rename-Item -NewName {"Test.exe"}
EOH
end
I also tried this, calling the PS script:
cookbook_file 'getbuild.ps1' do
mode '0755'
end
This looks like a windows remoting problem, your powershell needs the right configuration to be allowed to access network shares.
To verify if this is the case: replace the UNC path and just copy a local directory - if this works you can dig further to setup the requirements for windows remoting, see the following links for further help:
Safely running windows automation operations that fail inside winrm or powershell remoting (see chapter No access to network resources)
Knife issue 655
enabling and using credssp
To sum these links up: you can schedule a local task in your PS which does the copy to achieve this, or setup credssp.

Powershell Copy-item command not working in script although it does work when run from a command line

I am on a Windows 7 machine trying to execute a PowerShell script to copy a template directory to another directory. The command I am executing looks like:
Copy-Item -path "$projectsFolder$SourceFolder" -destination "$Test" -recurse -verbose;
The parameters are as follows:
path: C:\Users\username\Documents\Visual Studio 2010\Projects\TemplateSolution\Source
Destination: C:\Users\username\Documents\Visual Studio 2010\Projects\test\source\main
When I run this command at a PowerShell prompt, the files are copied correctly. If I try and execute the command in the script with verbose enabled, it appears to copy the files and directories, but only the top level directory is created in the file system. I am not sure why this would happen and I would appreciate any guidance or troubleshooting steps to perform.
Make sure you put quotes around the directory names if they have spaces in them. Also, you may need the -Force parameter to create destination directories if they do not exist.