Misc. on Power Shell Script

Misc. on Power Shell Script

How to read data from users?

Read-Host

How to write/print output data/text to the user:

Write-Output

How to Check if a file exists?

Test-Path $filePath

How to append data to a file?

Add-Content -Path $filePath -Value “x: $x, y: $y”

How to create a file?

New-Item -Path $filePath -ItemType File -Force

How to write content to a file?

Set-Content -Path $filePath -Value “x: $name, y: $age”

How to get a list of all files in a directory

$files = Get-ChildItem -Path $dirPath

How to find the size of a file?

$file.Length

How to append content to a file?

$content | Out-File -FilePath $outputFile -Append

How to Create a file and write content to it?

$content | Out-File -FilePath $outputFile