Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Need Help with setting a variable from a text file

$
0
0

below is the script I'm working on. for some reason I can't set the values in the text file to a variable or it's not working as intended.

 

$path= gc "C:\Users\csing001\Desktop\install\move.ini"
$path[0]
$des= gc "C:\Users\csing001\Desktop\install\move.ini"
$des[1]
$job= gc "C:\Users\csing001\Desktop\install\move.ini"
$job[2]

#####Define body as variable###########
[System.string]$pfiles
[System.string]$dfiles

#######################################

 try{test-path  -PathType Container $path, $des

}
catch{

}

Finally{

$pfiles = get-ChildItem -path $path -filter "*.txt"|sort-object|ConvertTo-Html -Property DirectoryName, LastWriteTime, Name|out-string

get-childitem -path $path $path -filter "test*.*"|Move-Item -Destination $des -ea 1

 

Contents of move.ini

C:\Users\csing001\Desktop\install

C:\Users\csing001\Desktop\move2

Payment Files

 

Error

Get-ChildItem : Cannot find path 'U:\Payment Files' because it does not exist.At line:34 char:11
+ $pfiles = get-ChildItem -path $path -filter "test*.*"|sort-object|ConvertTo-Html ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (U:\Payment Files:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
 
Move-Item : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Destination'. Specified method is not
supported.At line:36 char:68
+ get-childitem -path $path -filter "test*.*"|Move-Item -Destination $des
+                                                                    ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Move-Item], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.MoveItemCommand
 
Get-ChildItem : Cannot find path 'U:\Payment Files' because it does not exist.At line:42 char:11
+ $dfiles = get-ChildItem -path $des -filter "*.txt" |ConvertTo-Html -As List -Tit ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (U:\Payment Files:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles