Reputation: 6391
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
Upvotes: 1
Views: 159
Reputation: 60918
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.
Upvotes: 2