# Array brackets \[\] with an offset value starting at 0 returns error

**URL:** <https://forums.powershell.org/t/array-brackets-with-an-offset-value-starting-at-0-returns-error/22943>\
**Category:** PowerShell Help\
**Created:** [October 2, 2023, 5:13pm UTC](https://forums.powershell.org/t/array-brackets-with-an-offset-value-starting-at-0-returns-error/22943 "2023-10-02T17:13:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eliassal2](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@eliassal2](https://forums.powershell.org/u/eliassal2)\
**Post date:** [October 2, 2023, 5:13pm UTC](https://forums.powershell.org/t/array-brackets-with-an-offset-value-starting-at-0-returns-error/22943/1 "2023-10-02T17:13:03Z")

</div>

I use sqlserver psdrive, then I cd to databases and issue the following

```auto
$a = Dir | ?{$_.Schema -eq "$schemaname" } | ft Name, RowCount, DataSpaceUsed, IndexSpaceUsed -Auto

```

Typing $a I get 4 or 5 records. checked the $a type and I get

```auto
$a.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array

```

So It is an array.  
Trying to acces 1st item using $a[0] I get nothing, doing $a[1], I get an error

```auto
> Object reference not set to an instance of an object.
> + CategoryInfo : NotSpecified: (:) [out-lineoutput], NullReferenceException
> + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.OutLineOutputCommand

```

What am I doing wrong? Thanks

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [October 2, 2023, 5:27pm UTC](https://forums.powershell.org/t/array-brackets-with-an-offset-value-starting-at-0-returns-error/22943/2 "2023-10-02T17:27:16Z")

</div>

Don’t pipe to a `Format-*` cmdlet unless you’re outputting the data.

Also, avoid aliases in scripts (and in forum posts 🙂 ) because they’re harder to read and debug.

---

<div class="post-metadata">

**Author:** ![eliassal2](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@eliassal2](https://forums.powershell.org/u/eliassal2)\
**Post date:** [October 2, 2023, 5:50pm UTC](https://forums.powershell.org/t/array-brackets-with-an-offset-value-starting-at-0-returns-error/22943/3 "2023-10-02T17:50:45Z")

</div>

OK great, yes I removed the formatting and now the array is working fine. Do you mean aliases like “ft”?

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [October 2, 2023, 7:56pm UTC](https://forums.powershell.org/t/array-brackets-with-an-offset-value-starting-at-0-returns-error/22943/4 "2023-10-02T19:56:31Z")

</div>

> [@eliassal2](#):
>
> Do you mean aliases like “ft”?

Yes, `?` and `ft`.

[PowerShell Practice and Style Guide - Naming Conventions](https://github.com/PoshCode/PowerShellPracticeAndStyle/blob/master/Style-Guide/Naming-Conventions.md)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:14pm UTC](https://forums.powershell.org/t/array-brackets-with-an-offset-value-starting-at-0-returns-error/22943/5 "2024-05-16T20:14:38Z")

</div>


