Posh-SSH icon indicating copy to clipboard operation
Posh-SSH copied to clipboard

Get-SFTPChildItem: Can't assign LastWriteTime of file to a [DateTime] variable

Open MickeyDamn opened this issue 2 years ago • 2 comments

This works as expected: Get-SFTPChildItem -SessionID $SFTP_Session.SessionID -Path /home/wd/UPDATES/ -Recurse -File | select LastWriteTime -expandproperty LastWriteTime

This doesn't work, variable = $null: [DateTime] $FileLastWrite = Get-SFTPChildItem -SessionID $SFTP_Session.SessionID -Path /home/wd/UPDATES/ -Recurse -File | select LastWriteTime -expandproperty LastWriteTime

Many thanks for creating this module!

MickeyDamn avatar Jan 17 '24 20:01 MickeyDamn

The command is processing multiple files, each returning s value, so a collection is being returned but you are casting a single value, I would move the casting for datetime at the end of the pipes Sent from my iPhoneOn Jan 17, 2024, at 4:04 PM, MickeyDamn @.***> wrote: This works as expected: Get-SFTPChildItem -SessionID $SFTP_Session.SessionID -Path /home/wd/UPDATES/ -Recurse -File | select LastWriteTime -expandproperty LastWriteTime This doesn't work, variable = $null: [DateTime] $FileLastWrite = Get-SFTPChildItem -SessionID $SFTP_Session.SessionID -Path /home/workday/AD_UPDATES/ -Recurse -File | select LastWriteTime -expandproperty LastWriteTime Many thanks for creating this module!

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

darkoperator avatar Jan 18 '24 00:01 darkoperator

Thank you for the reply and advice!

MickeyDamn avatar Jan 18 '24 15:01 MickeyDamn