1

I'm trying to do something very simple, but with being new to powershell I'm having trouble figuring out what is wrong:

PS C:\Windows\system32> $directoryMaker = New-Object [System.IO.Directory]::CreateDirectory("C:\test")
New-Object : Cannot find type [[System.IO.Directory]::CreateDirectory]: make sure the assembly containing this type is loaded.
At line:1 char:19
+ $directoryMaker = New-Object [System.IO.Directory]::CreateDirectory("C:\test")
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
nullByteMe
  • 6,141
  • 13
  • 62
  • 99

1 Answers1

2

try just:

$directoryMaker = [System.IO.Directory]::CreateDirectory("C:\test")

In this case you are using a static method ( CreateDirectory(string s) ) of the [System.IO.Directory] then you don't need to instantiate a [System.IO.Directory] object to reference the new folder created by this method itself.

Community
  • 1
  • 1
CB.
  • 58,865
  • 9
  • 159
  • 159
  • Thanks a lot, I still haven't learned my way around powershell. – nullByteMe Sep 16 '13 at 12:19
  • 1
    @inquisitor This is more c# then Powershell, the powershell way is: `$directoryMaker = new-item -Path c:\test -type directory` – CB. Sep 16 '13 at 12:21
  • Yeah I was experimenting with C# because I have to do some custom things with streams and wanted to make sure I understood how to do something more simple. Thanks so much! – nullByteMe Sep 16 '13 at 12:24