Solved

powershell psobject

Posted on 2016-07-18
10
38 Views
Last Modified: 2016-07-26
Hi experts.
I want to compare a file on a server with one that is newer (same name but version difference) so I am trying to compare the files version, and if the same version do nothing, if older install newer file.
I have been looking at psobject -property but to be honest PS is not my strength, if the file resides :
\\SERVER1\files\myfile   and the version is 1.
my new file is also called myfile and it's version is version 2. can anyone give me the command I would use please? I'm not one for trying this site everything a problem occurs but as said PS isn't me and it could take me hours to get the answer through googling.
thank you all.
0
Comment
Question by:Jason Thomas
  • 5
  • 3
  • 2
10 Comments
 
LVL 39

Assisted Solution

by:footech
footech earned 167 total points
ID: 41717514
How is the version of the file designated?  Does it show in the file's versioninfo like
gi \\SERVER1\files\myfile | Select -expand VersionInfo | Select FileVersion

Open in new window


Depending on the answer you may be looking at different ways of comparing a file, like comparing dates, file hashes, etc.
0
 
LVL 83

Assisted Solution

by:oBdA
oBdA earned 333 total points
ID: 41717544
The correct way to do it depends on the way your actual file defines the version string.
If it's the usual convention of a maximum of 4 int32 separated by '.', it's not difficult.
$OldFile = Get-Item -Path '\\SERVER1\files\myfile'
$NewFile = Get-Item -Path '\\SERVER1\NewFiles\myfile'
If ([version]$OldFile.VersionInfo.FileVersion -lt [version]$NewFile.VersionInfo.FileVersion) {
	Copy-Item -Path $NewFile.FullName -Destination $OldFile.FullName -Force -WhatIf
}

Open in new window

Or if the file date will reflect older/newer:
$OldFile = Get-Item -Path '\\SERVER1\files\myfile'
$NewFile = Get-Item -Path '\\SERVER1\NewFiles\myfile'
If ($OldFile.LastWriteTime -lt $NewFile.LastWriteTime) {
	Copy-Item -Path $NewFile.FullName -Destination $OldFile.FullName -Force -WhatIf
}

Open in new window

0
 
LVL 1

Author Comment

by:Jason Thomas
ID: 41717576
thank you very much. and I can save that as a script and run from schedule task?
0
 
LVL 1

Author Comment

by:Jason Thomas
ID: 41717580
hi@fotech. sorry I'm on a mobile and only saw the second response through my screen. it checks for versions.
0
 
LVL 39

Expert Comment

by:footech
ID: 41717597
??
it checks for versions.
I don't know what that means.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 1

Author Comment

by:Jason Thomas
ID: 41717604
Hi. first of it looks like my responses are appearing more than once, could be the new EE app I'm using I have no idea. To clarify further as I realise my version answer was a bit vague. so, we look are looking at the file properties, details tab, and "product version" property.
thank you chaps.
0
 
LVL 39

Expert Comment

by:footech
ID: 41717612
oBdA's should work for you then.  Just change FileVersion to ProductVersion.
0
 
LVL 1

Author Comment

by:Jason Thomas
ID: 41719413
Hi both still looking at this. What one liner can I use to pull the file version info for a file? I just want to be able to test and check the version outside of a script.
Thank you.
0
 
LVL 83

Accepted Solution

by:
oBdA earned 333 total points
ID: 41719417
(Get-Item 'C:\Windows\explorer.exe').VersionInfo.ProductVersion

Open in new window

0
 
LVL 1

Author Closing Comment

by:Jason Thomas
ID: 41728999
Brilliant as always. Hope point share seems fair.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need to query users with Skype Online 4 19
Identify disabled AD users with PowerShell 6 39
Simple Q for someone 3 19
Powershell error when I create new user 3 29
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now