Thats it! Superb. Thanks Jaykul, it never occurred to me that
the invoke-expression cmdlet was also unwrapping. Must watch out
for that.
Many thanks,
Stuart
On 3 Nov, 13:32, "Jaykul" <Jay...@xxxxxx> wrote:
> It's because your variable actually gets unwrapped when you put it into
> $con, and then again by Invoke-Expression. *You should be able to avoidthe
> first unwrapping by single-quoting it:
>
> $con = '.\mbsacli /target $target /u $username /p $password /nd /n '
>
> --
> Joel "Jaykul" Bennetthttp://HuddledMasses.org/
> qotd: However, never daunted, I will cope with adversity in my traditional
> manner ... sulking and nausea. -- Tom K. Ryan
>
> "Kryten" <Kryte...@xxxxxx> wrote in message
>
> news:634dd4cc-83a2-42d1-9cb5-f39ab5eeb531@xxxxxx
>
>
>>
> > I'm using Powershell to generate MBSAcli scan strings. Been working
> > great forever, till today! >
> > Turns out that a username on a particular box was as shown
> > below...this was causing
> > Invoke-Expression to crash out with a "cannot index into a null array"
> > error. >
> > I mean, what were the chances of someone picking a username the same
> > as a powershell array? >
> > Set-Location "C:\Pro* Fil*\Micro*Bas*"
> > [string]$username = '$User[5]'
> > [string]$password = 'mypassword'
> > $path = "C:\test.txt"
> > $target = "myhost"
> > $con = ".\mbsacli /target $target /u $username /p $password /nd /n "
> > "IIS+OS+SQL" " /catalog " "C:\MBSACatalog\wsusscn2.cab" " > $path" >
> > Invoke-Expression $con >
> > Seems like the Powershell parser is interpreting $user[5] as an array,
> > not a simple string value while execute the invoke-expression cmdlet
> > and trying to index into it. >
> > Would be grateful for any suggestions for how to deal with this in an
> > elegant way. >
> > Thanks,
> > Stuart- Hide quoted text - >
> - Show quoted text -