Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - How to exit script?

Reply
 
Old 10-29-2009   #1 (permalink)
Martin Zugec


 
 

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 SpecsSystem Spec
Old 10-29-2009   #2 (permalink)
Martin Zugec


 
 

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 SpecsSystem Spec
Old 10-29-2009   #3 (permalink)
Martin Zugec


 
 

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 SpecsSystem Spec
Old 10-29-2009   #4 (permalink)
Rob Campbell


 
 

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 SpecsSystem Spec
Old 10-29-2009   #5 (permalink)
Martin Zugec


 
 

Re: How to exit script?

Hi Rob,

suddenly not, even this doesn't work:
S4Matic.ps1 -ConsoleMode; MkDir "C:\Temp\yyy"

Martin
My System SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46