When trying to dot source the file to bring the function into PowerShell, it fails with the following errors:
At C:\PowerShellScripts\Get-BatteryLevel\Get-BatteryLevel.ps1:13 char:20
+ write-host "â–‘" -NoNewline
+ ~~~~~~~~~~~~~
The string is missing the terminator: '.
At C:\PowerShellScripts\Get-BatteryLevel\Get-BatteryLevel.ps1:9 char:35
+ if ($_ -le $BatteryLevel) {
+ ~
Missing closing '}' in statement block or type definition.
At C:\PowerShellScripts\Get-BatteryLevel\Get-BatteryLevel.ps1:8 char:28
+ 0..10 | ForEach-Object {
+ ~
Missing closing '}' in statement block or type definition.
At C:\PowerShellScripts\Get-BatteryLevel\Get-BatteryLevel.ps1:1 char:27
+ function Get-BatteryLevel {
+ ~
Missing closing '}' in statement block or type definition.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
I'm not sure why this happens but it appears to be related to one of the symbols used for the battery life indicator.
If you copy and paste the function into PowerShell, it works fine.
If you include the text of the function in your PowerShell profile then it works fine. See my PowerShell Profile.