开发者

powershell wrapping long file paths

i have a script running fine in a powershell window but not when ran as a script, where lines are "wrapped", screwing the variables contents.

basically a part of my code looks like this :

Get-AIPFileStatus -Path $Path | Where-Object {$_.IsRMSProtected -eq 'True'}  | Out-String -Stream -width 4096 | Select-String "^(FileName|FilePath) +: +(.*)$" 

and instead of getting an output such as this one :

FileName        : Z:\long_path_here\long_path_here\long_path_here\long_path_here\file_name01.xlsx
FileName        : Z:\long_path_here\long_path_here\long_path_here\long_path_here\file_name02.xlsx
FilePath        : Z:\long_path_here\long_path_here\long_path_here\long_path_here\file_name03.xlsx
FileName        : Z:\long_path_here\long_path_here\long_path_here\long_path_here\file_name04.xlsx
FilePath        : Z:\long_path_here\long_path_here\long_path_here\long_path_here\file_nameN.xlsx

the script instead generates :

FileName        : Z:\long_path_here\long_path_here\long_path_here\long_path_here\
file_name01.xlsx
FileName        : Z:\long_path_here\long_path_here\long_path_here\long_path_here\
file_name02.xlsx
FilePath        : Z:\long_path_here\long_path_here\long_path_here\long_path_here\
file_name03.xlsx
FileName        : Z:\long_path_here\long_path_here\long_path_here\long_path_here\开发者_StackOverflow社区
file_name04.xlsx
FilePath        : Z:\long_path_here\long_path_here\long_path_here\long_path_here\
file_nameN.xlsx

which is messing up my loop afterwards (as i need the full file name), e.g. my code :

Get-AIPFileStatus -Path $Path | Where-Object {$_.IsRMSProtected -eq 'True'} | Out-String -Stream -width 4096 | Select-String "^(FileName|FilePath) +: +(.*)$" | ForEach-Object{$_.Matches.Groups[2].Value} |
Foreach-Object {
   $file = $_
   Write-Host -NoNewline "File '$file' has encryption enabled, trying to remove it.."
   Set-AIPFileLabel -LabelId $UID -Path $file -PreserveFileDetails -JustificationMessage "blablabla" 
   if( $? ) {
      Write-Host "SUCCESS"
   } else {
      Write-Host "FAILED"
   }
}

the variable "$file" above is only getting a small piece of the file path. in short, i just want to get file paths from the output of Get-AIPFileStatus and apply something on them, but because of this wrapping this is messing up the script as the final result is that the file path "taken" from the script is for example :

Z:\long_path_here\long_path_here\long_path_here\long_path_her

instead of :

Z:\long_path_here\long_path_here\long_path_here\long_path_here\file_name01.xlsx

how can i fix that ? thanks again regards,

PS : this is my first ever powershell script, be nice :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜