我正在尝试做一些非常简单的事情,但是对于PowerShell的新手,我无法弄清楚出了什么问题:
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
答案 0 :(得分:2)
尝试:
$directoryMaker = [System.IO.Directory]::CreateDirectory("C:\test")
在这种情况下,您使用CreateDirectory(string s)
的{{3}}([System.IO.Directory]
),然后您不需要实例化[System.IO.Directory]
对象来引用创建的新文件夹通过这种方法本身。