Posted On March 31, 2019

PowerShell: Error when Pause is Placed Inside Function

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Error when Pause is Placed Inside Function

Error:

+ Function Search-ScheduledTasks{
+ ~
Missing closing '}' in statement block or type definition.
At C:\Users\kdoan\Desktop\Notes\test.ps1:57 char:1
+ } #end Search function
+ ~
Unexpected token '}' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndCurlyBrace

Cause:

Function test{
ping google.com;
pause;
}


Fix: Remove the pause command

Function test{
ping google.com;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Basic CSS: Set the id of an Element

<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css"><style> .red-text { color: red; } h2 { font-family: Lobster, monospace; }…

PowerShell: Set VM Dynamic Memory in Virtual Machine Manager

# setVmDynamicMemoryInVmm.ps1 # Optimize Dynamic RAM $minGb='16GB' $maxGb='32GB' $startupGb='2GB' $buffer=20 $memoryWeight=5000 $forcedRestart=$false $vmmServer='localhost' function getUnoptimizedMemoryVms{…

PowerShell: Use Win-SCP to Download Files from SFTP Server

Version 2: # downloadFilesViaSftp.ps1 # Version 0.0.2 # # Description: # This simple script is…