![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | How to exit script? Hi gents, I got following command line: "C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe" -Command "c:\Temp\S4Matic\S4Matic\S4Matic.ps1" -ConsoleMode; S4M\Import-Job - ContainersFolder "c:\Temp\S4Matic\Containers" -Job "c:\Temp\S4Matic \Jobs\Default\XenAppMaintenance" -Profile "DHL_CZCHO_XA5_T" - TargetFolder "c:\temp\yyy" To simplify it: 1.) first line will call S4matic.ps1 with switch argument - ConsoleMode. This will load all the functions. 2.) Second line (or token) will execute function that was loaded using S4Matic.ps1 Suddenly, I run into following problem: The variable '$_' cannot be retrieved because it has not been set. At line:50 char:38 + $steppablePipeline.Process($_ <<<< ) + CategoryInfo : InvalidOperation: (_:Token) [], Parent rorRecordException + FullyQualifiedErrorId : VariableIsUndefined Line where it fails is pretty standart: If (!$(Test-Path $TargetFolder)) {MkDir $TargetFolder | Out-Null} I don't see anything wrong here and got no idea why it doesn't work?? Thanks, Martin |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How to exit script? Just small update - even MkDir alone fails ![]() DEBUG: ! CALL function 'mkdir' DEBUG: 36+ try <<<< { DEBUG: 37+ $wrappedCmd = <<<< $ExecutionContext.InvokeCommand.GetCommand('New-Item', [System.Management.Automation.CommandTypes]::Cmdlet) DEBUG: ! CALL method 'System.Management.Automation.CommandInfo GetCommand(string commandName, System.Management.Automation.CommandTypes type)' DEBUG: ! SET $wrappedCmd = 'New-Item'. DEBUG: 38+ $scriptCmd = <<<< {& $wrappedCmd -Type Directory @PSBoundParameters } DEBUG: ! SET $scriptCmd = '& $wrappedCmd -Type Directory @PSBoundParameters '. DEBUG: 39+ $steppablePipeline = <<<< $scriptCmd.GetSteppablePipeline() DEBUG: ! CALL method 'System.Management.Automation.SteppablePipeline GetSteppablePipeline()' DEBUG: ! SET $steppablePipeline = 'System.Management.Automation.SteppablePipel...'. DEBUG: 40+ $steppablePipeline.Begin <<<< ($PSCmdlet) DEBUG: ! CALL method 'System.Void Begin(System.Management.Automation.Internal.InternalCommand command)' DEBUG: ! CALL function 'mkdir' DEBUG: 49+ try <<<< { DEBUG: 50+ $steppablePipeline.Process <<<< ($_) DEBUG: ! Trap or Catch generic; caught [System.Management.Automation.RuntimeException] DEBUG: 52+ throw <<<< The variable '$_' cannot be retrieved because it has not been set. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How to exit script? +1 more thing - first script (S4Matic.ps1) is existing by calling Return: If ($ConsoleMode) {S4M\Load-Module -Name "ConsoleMode";Write-Host; Write-Host -ForegroundColor Green "S4Matic console mode loaded"; return} When I tried to use Break, rest of items after ";" are not processed at all (and Exit of course close powershell.exe) |
My System Specs![]() |
| | #4 (permalink) |
| | RE: How to exit script? It doesn't seem to like having that pipeline there. Does this work any better: If (!$(Test-Path $TargetFolder)) {[void](MkDir $TargetFolder)} "Martin Zugec" wrote: Quote: > Hi gents, > > I got following command line: > "C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe" -Command > "c:\Temp\S4Matic\S4Matic\S4Matic.ps1" -ConsoleMode; S4M\Import-Job - > ContainersFolder "c:\Temp\S4Matic\Containers" -Job "c:\Temp\S4Matic > \Jobs\Default\XenAppMaintenance" -Profile "DHL_CZCHO_XA5_T" - > TargetFolder "c:\temp\yyy" > > To simplify it: > 1.) first line will call S4matic.ps1 with switch argument - > ConsoleMode. This will load all the functions. > 2.) Second line (or token) will execute function that was loaded using > S4Matic.ps1 > > Suddenly, I run into following problem: > The variable '$_' cannot be retrieved because it has not been set. > At line:50 char:38 > + $steppablePipeline.Process($_ <<<< ) > + CategoryInfo : InvalidOperation: (_:Token) [], Parent > rorRecordException > + FullyQualifiedErrorId : VariableIsUndefined > > Line where it fails is pretty standart: > If (!$(Test-Path $TargetFolder)) {MkDir $TargetFolder | Out-Null} > > I don't see anything wrong here and got no idea why it doesn't work?? > > Thanks, > Martin > > . > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: How to exit script? Hi Rob, suddenly not, even this doesn't work: S4Matic.ps1 -ConsoleMode; MkDir "C:\Temp\yyy" Martin |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| exit | PowerShell | |||
| Help Getting Exit Codes... | PowerShell | |||
| Obtaining Script Exit Return Codes | PowerShell | |||
| exit out of a PowerShell script in a IF block | PowerShell | |||
| .NET 1.1 exe remains in-use after exit | Vista networking & sharing | |||