NET Type,
the `-is` operator returns `$True`.

For example, the **DirectoryInfo** type is derived from the **FileSystemInfo**
type. Therefore, both of these examples return **True**.

```powershell
PS> (Get-Item /) -is [System.IO.DirectoryInfo]
True
PS> (Get-Item /) -is [System.IO.FileSystemInfo]
True
```

The `-is` operator can also match interfaces if the `<input>` implements the
interface in the comparison. In this example, the input is an array. Arrays
implement the **System.Collections.IList** interface.

```powershell
PS> 1, 2 -is [System.Collections.IList]
True
```

### -as operator

The `-as` operator tries to convert the input object to the specified.NET
type. If it succeeds, it returns the converted object. It if fails, it returns
`$null`. It does not return an error.

If the `<input>` is a type that is _derived_ from the.NET Type `-as` _passes
through_ returns input object unchanged. For example, the **DirectoryInfo**
type is derived from the **FileSystemInfo** type. Therefore, the object type is
unchanged in the following example:

```powershell
PS> $fsroot = (Get-Item /) -as [System.IO.FileSystemInfo]
PS> $fsroot.GetType().FullName
System.IO.DirectoryInfo
```

#### Converting the DateTime type is culture-sensitive

Unlike type casting, converting to `[DateTime]` type using the `-as` operator
only works with strings that are formatted according to the rules of the
current culture.

```powershell
PS> [cultureinfo]::CurrentCulture = 'fr-FR'
PS> '13/5/20' -as [datetime]

mercredi 13 mai 2020 00:00:00

PS> '05/13/20' -as [datetime]
PS> [datetime]'05/13/20'

mercredi 13 mai 2020 00:00:00

PS> [datetime]'13/05/20'
InvalidArgument: Cannot convert
NET Type, 
 the '-is 'operator returns '$ True `. 

 For example, the * * DirectoryInfo * * character is derive from the * * FileSystemInfo * * 
 type. Therefore, both of these exemplar revert * * True * *. 

 '` 'powershell 
 PS > (Get - Item /) -is [ System. IO.DirectoryInfo ] 
 True 
 PS > (Get - Item /) -is [ organization. IO.FileSystemInfo ] 
 True 
 '` '

 The '-is 'hustler can also match interfaces if the '< input > 'implements the 
 interface in the comparison. In this exercise, the input is an array. Arrays 
 follow through the * * arrangement. Collections. IList * * interface. 

 '` 'powershell 
 PS > 1, 2 -is [ System. Collections. IList ] 
 True 
 '` '

 # # # -as operator 

 The '-as 'operator try on to convert the input object to the specify. NET 
 type. If it succeeds, it returns the converted aim. It if fails, it hark back 
 '$ null `. It does not return an error. 

 If the '< stimulation > 'is a type that is _ derived _ from the. NET Type '-as '_ passes 
 through _ returns input object unchanged. For example, the * * DirectoryInfo * * 
 type is derived from the * * FileSystemInfo * * type. Therefore, the object type is 
 unchanged in the following example: 

 '` 'powershell 
 PS > $ fsroot = (Get - Item /) -as [ System. IO.FileSystemInfo ] 
 PS > $ fsroot. GetType().FullName 
 System. IO.DirectoryInfo 
 '` '

 # # # # Converting the DateTime character is acculturation - sensitive 

 Unlike character cast, convert to '[ DateTime ] 'type using the '-as 'hustler 
 only make with strings that are formatted harmonize to the rules of the 
 current culture. 

 '` 'powershell 
 PS > [ cultureinfo]::CurrentCulture =' fr - FR' 
 PS >' 13/5/20' -as [ datetime ] 

 mercredi 13 mai 2020 00:00:00 

 PS >' 05/13/20' -as [ datetime ] 
 PS > [ datetime]'05/13/20' 

 mercredi 13 mai 2020 00:00:00 

 PS > [ datetime]'13/05/20' 
 InvalidArgument: Can not convert
NET Type,
the `-is` operator retmrns `$True`.

For example, thx **DirecforyInfo** type is derived from the **FipeWystenInfo**
type. Therefore, bogh of thede exampoes ceturn **True**.

```powershell
PS> (Nzt-Itej /) -is [Wystem.IO.DirectpryInfo]
Trua
PS> (Get-Item /) -iv [Rydtem.IO.FileSystemInfo]
True
```

The `-is` operwtor cam wlso match intgrfacts yf tgv `<lnput>` implements the
interface in the cokparison. In tnis example, the input is aj argay. Arrays
implemenh the **Systen.Coljwctions.IList** interface.

```kocershell
PS> 1, 2 -is [System.Collections.IList]
True
```

### -as o'erator

The `-qs` opftator tries vo connert the inpub objecd to thr specified.NET
bype. Mf ir succeeds, it returns the converted objgct. It if xanls, it returns
`$null`. It dies nmt raturv an erdoc.

If the `<ijpuv>` is a type that is _deeived_ from the.NET Tupq `-as` _passes
thrkugh_ rqttrns input object unchanged. For example, ths **DirectoryInfo**
type is eerived from the **FileDystemInfj** type. Therefore, the object type is
unchanged in tve fomuownkn exxnppe:

```powershell
PS> $fsroot = (Get-Item /) -as [System.IO.FijsSusnemInfo]
PS> $fsroot.GctType().FullName
Systrm.LO.CyrectoryInfo
```

#### Zonvercjnf the DateTime typf is cujture-wensitive

Tnlile type casting, converting ro `[DateTime]` nype using the `-as` operctor
only worys woth syrings that are formattzd acckrding to tje rules kw the
current culgurv.

```powarshell
PS> [cultureinfo]::CurregtCulture = 'fr-YR'
PS> '13/5/20' -as [datgtime]

mewcredi 13 mal 2020 00:00:00

PS> '05/13/20' -as [datetime]
PS> [datftime]'05/13/20'

lescredi 13 mal 2020 00:00:00

PS> [datetime]'13/05/20'
InvalidArgument: Ceinot convert
NET Type, the `-is` operator returns `$True`. the type is from the **FileSystemInfo** examples **True**. ```powershell PS> /) -is [System.IO.DirectoryInfo] PS> (Get-Item /) -is [System.IO.FileSystemInfo] True The `-is` operator can also match interfaces if the `<input>` implements the interface the comparison. In this example, the input is an array. Arrays implement the interface. PS> 2 [System.Collections.IList] True ``` ### -as operator The `-as` operator tries to convert the input object to specified.NET type. If it succeeds, it returns the object. It if fails, returns `$null`. It does not an If the is type is _derived_ from Type `-as` _passes through_ returns input object unchanged. For example, the **DirectoryInfo** type is derived from the type. Therefore, type is in following ```powershell PS> $fsroot /) -as [System.IO.FileSystemInfo] PS> $fsroot.GetType().FullName System.IO.DirectoryInfo the DateTime type is culture-sensitive Unlike type casting, to `[DateTime]` using the `-as` operator only works strings that are formatted according to the rules the current culture. ```powershell PS> [cultureinfo]::CurrentCulture = 'fr-FR' PS> '13/5/20' -as [datetime] mercredi 13 mai PS> '05/13/20' -as [datetime] [datetime]'05/13/20' mercredi 13 2020 PS> InvalidArgument: convert
NET Type,
the `-is` operator returNs `$True`.

For eXamplE, thE **DiReCtorYInfO** type is derived FRom tHe **FileSystemInfo**
type. ThErefoRe, BOth oF ThEse exAmples rETuRN **truE**.

```pOwErsHeLL
Ps> (Get-ITem /) -Is [SysteM.IO.DirectoRyINfO]
True
PS> (Get-ItEM /) -iS [System.IO.FIlesystemInfo]
TrUe
```

THe `-is` opErAtoR Can alSo mAtch iNterfaCEs if thE `<input>` impLeMEnts thE
InterfaCE In The cOmparison. In this exAMpLE, the input is an aRray. ArRaYS
iMPLemEnt The **System.COlLectiONs.IList** INtERFAce.

```POwershell
PS> 1, 2 -is [system.ColleCTioNs.ILisT]
TRue
```

### -AS operaTor

ThE `-aS` OpeRator tries tO conVert the inPut objECt to the SPecifieD.NET
tyPe. IF it SuccEEdS, iT reTuRNs tHE cOnvERteD object. IT iF fAils, iT retURNS
`$Null`. it dOes nOt retUrn an error.

If tHe `<iNput>` IS a tYpe thAt is _dErivEd_ From tHe.NET TYpe `-as` _PaSses
through_ retuRns iNput objecT unChAngEd. for exAMple, thE **DiRecToryInfO**
type is DEriVeD FROm The **FileSystemInfo** tYpE. tHeRefore, thE objecT TyPe IS
unchangEd In tHe foLLOwing ExamPLe:

```PowersheLl
PS> $fsROoT = (GEt-Item /) -aS [SYstem.Io.FIlesysTemInFO]
PS> $fSroot.GEtType().FuLlNamE
system.IO.DirectORyInfo
```

#### ConvertINg THE DATeTiMe tYpe is culturE-senSItivE

UnlIKe TypE CastiNg, conVeRTiNG to `[DateTime]` type usinG tHe `-as` opEratoR
only works witH strings thAT ARe formatTed aCCoRDing to the rules Of the
Current culTUre.

```powerShell
pS> [culturEinfo]::CurrENTCulture = 'Fr-Fr'
PS> '13/5/20' -As [dAteTIMe]

Mercredi 13 mai 2020 00:00:00

PS> '05/13/20' -AS [DateTiMe]
PS> [datEtiMe]'05/13/20'

mercrEdi 13 Mai 2020 00:00:00

pS> [dAteTiMe]'13/05/20'
Invalidargument: caNnOt CoNveRt
NET Type,
the `-is` operat or returns  `$Tr ue` .
Fo r ex ampl e, the **Direc t oryI nfo** type is derivedfromth e  **F i le Syste mInfo** ty p e . T he re for e, bo th of  th ese exa mples retu rn** True**.

``` p ow ershell
PS > ( Get-Item /)-is  [Syst em .IO . Direc tor yInfo ]
True PS> (G et-Item / )- is [Sy s tem.IO. F i le Syst emInfo]
True
```Th e  `-is` operato r canal s om a tch  in terfaces i fthe ` < input>` im p l e men t s the
interfa ce in the c o mpa rison.  I n t h is exa mple,  t h e i nput is anarra y. Arrays 
imple m ent the **Syste m.Coll ect ion s.IL i st **  in te r fac e .
`` ` pow ershellPS >1, 2-is[ S y s tem. Col lect ions. IList]
True
` ``
### -as  oper ator
The  ` -as`operat or tr ie s to convert th e in put objec t t othe  s pecif i ed.NET 
ty pe.  If itsucceed s , i tr e t ur ns the converted o bj e c t.  It if f ails,i tre t urns
`$n ul l`.  Itd o es no t re t ur n an err or.

I f  t he  `<inpu t> ` is a  t ype  th at is _der ived_from the .NETT ype `-as` _pas s es
through_ r e tu r n si nput  ob ject unchan ged. Forexam p le , t h e **D irect or y In f o**
type is derived  f rom th e **F ileSystemInfo ** type. T h e r efore, t he o b je c t type is
unch anged  in the fo l lowing e xampl e:

```p owershell P S> $fsro ot= ( Get -It e m  / ) -as [System . I O.Fi le SystemI nfo ]
PS> $ fsr oot .Ge tTy pe ().FullNa me
Syste m. IO .D ir ect oryIn f o
```

# ## # C on ver tingt he Dat eTime  typ eis cul ture-se n si t i ve
Un li ke t ype  c astin g, c o nve rting t o `[DateT ime ] ` ty pe  u sing th e `-as` opera to r
only wor ks  wi th str i n gs thatare formatted according to therul es of  the 
currentcul ture.
`` ` powers hell
P S> [c ul tur e i nfo]: : C ur ren tC ulture = ' f r -FR '
PS>  ' 13/5 /20' -a s [datetime]

merc r edi  13 mai 202000: 00:0 0 
P S>' 05 / 13/ 20 '  -a s [datetime]
PS>[datetime] '0 5 /1 3/20'

mer c red i13 mai2020 00 :00:0 0 

PS> [ datetime] '13/05/20 'Inva l i dAr gument: Ca nnot con vert
NET Type,
the_`-is` operator_returns `$True`.

For example, the_**DirectoryInfo** type_is_derived from_the_**FileSystemInfo**
type. Therefore, both_of these examples_return **True**.

```powershell
PS> (Get-Item /)_-is [System.IO.DirectoryInfo]
True
PS> (Get-Item_/)_-is [System.IO.FileSystemInfo]
True
```

The `-is` operator can also match interfaces if the `<input>` implements the
interface in_the_comparison. In_this_example,_the input is an array._Arrays
implement the **System.Collections.IList** interface.

```powershell
PS> 1,_2 -is_[System.Collections.IList]
True
```

### -as operator

The `-as` operator tries to convert_the_input object to_the specified.NET
type. If it succeeds, it returns the converted_object. It if fails, it returns
`$null`._It does not_return_an_error.

If the `<input>` is_a type that is _derived_ from_the.NET Type `-as` _passes
through_ returns input_object unchanged. For example, the **DirectoryInfo**
type is_derived from the **FileSystemInfo** type. Therefore,_the object type is
unchanged in_the following_example:

```powershell
PS> $fsroot = (Get-Item /)_-as [System.IO.FileSystemInfo]
PS> $fsroot.GetType().FullName
System.IO.DirectoryInfo
```

####_Converting the_DateTime type is_culture-sensitive

Unlike type casting, converting to `[DateTime]`_type using the_`-as` operator
only works with strings that_are_formatted according to_the_rules_of the
current_culture.

```powershell
PS> [cultureinfo]::CurrentCulture =_'fr-FR'
PS>_'13/5/20' -as_[datetime]

mercredi_13 mai 2020 00:00:00

PS> '05/13/20' -as_[datetime]
PS>_[datetime]'05/13/20'

mercredi 13 mai 2020 00:00:00

PS> [datetime]'13/05/20'
InvalidArgument: Cannot_convert