Skip to content

Powershell Function example

This script add content to file

ps1
$FileName = "$($env:COMPUTERNAME).txt"
$FolderPath = "<folder_path>"
$Path = $FolderPath+$FileName

function WriteToFile {
  Param
  (
	[Parameter(Mandatory=$true, Position=0)]
	[string]$FullPath,
	[Parameter(Mandatory=$true, Position=1)]
	[string]$ContentToAdd
  )
	Add-Content $FullPath $ContentToAdd
	Add-Content $FullPath "`n" # new empy tline
}

# usage  :
WriteToFile -FullPath $Path -ContentToAdd "test test !"