Can't load a .NET type in PowerShell Can't load a .NET type in PowerShell powershell powershell

Can't load a .NET type in PowerShell


Your new-object syntax is a little off. Try this:

[System.Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices")$machine = new-object -typeName System.DirectoryServices.DirectoryEntry -argumentList "WinNT://localhost,computer"


There's no need to load anything. Use the adsi type accelerator:

[adsi]"WinNT://localhost,computer"


I think the syntax for New-Object is incorrect. Taken from [some documentation on New-Object]:1

New-Object System.DirectoryServices.DirectoryEntry("WinNT://localhost,computer")