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

cannot display csv file on screen after input, please help.

$
0
0

I am writing practice scripts from challenges for a test

 

1. Test to see if there are any files in the directory specified as the command line argument.

 

If there are no files in directory after user input, script will display " There are no files in directory"

 

If not, the script will create a csv file in that directory, if file exists, script will prompt for overwrite.

 

The csv file must contain full file name and file size in KB of all files in specified directory. It should look like this ...when specifying a directory when prompted

 

 

 

"File Name", "File Size(KB)"

 

"C:\windows\file.exe","23.0"

 

"C:\windows\file2.bin","6.0"

 

"etc, etc"

 

 

 

This is what i have so far, I only can get the error prompt to show up after input , but not the rest of the specification, what am i doing wrong here? Please help, thanks.

 

 

 

cls

 

$where=read-host "Enter a file path (e.g. C:\Temp)"

set-location $where -ErrorAction stop

 

 

 

$computer = "PC1"

 

$file = "c:\files.csv"

 

 

 

$available = test-connection $computer -quiet -count 1

 

 

 

if ($available -eq $false) {

 

 

 

    "$computer is not responding"

 

    exit

 

}

 

 

 

if ((test-path $file) -eq $true) {

 

 

 

    $response = read-host "$file exists. Should the file be overwritten? Type yes to overwrite"

 

    if ($response -ne "yes") { exit }

 

}

 

Get-childitem c:\windows -recurse | Select-Object -Property name, size | Export-Csv $file -NoTypeInformation

 

#######

Thank you everyone.

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles