Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Object 尝试使用powershell对象时出错_Object_Powershell - Fatal编程技术网

Object 尝试使用powershell对象时出错

Object 尝试使用powershell对象时出错,object,powershell,Object,Powershell,我正在尝试做一些非常简单的事情,但由于不熟悉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 conta

我正在尝试做一些非常简单的事情,但由于不熟悉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
试试看:

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

在这种情况下,您使用的是
[System.IO.Directory]
的(
CreateDirectory(string s)
),那么您不需要实例化
[System.IO.Directory]
对象来引用此方法本身创建的新文件夹。

非常感谢,我还没有学会如何使用powershell。@Insquisitor这更像是c#而powershell,powershell的方式是:
$directoryMaker=new item-Path c:\test-type directory
是的,我在用c#做实验,因为我必须用流做一些自定义的事情,并且想确保我了解如何做更简单的事情。非常感谢@检察官很乐意帮忙!!