Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.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
String Powershell脚本问题字符串_String_Powershell - Fatal编程技术网

String Powershell脚本问题字符串

String Powershell脚本问题字符串,string,powershell,String,Powershell,在控制台中将$Vendor作为创建文件夹的参数传递时,无法识别该$Vendor。它提供的错误字符串输入格式不正确。如果手动传递任何字符串,它将识别并创建具有该名称的文件夹。我尝试将$Vendor解析为字符串。您能帮助我吗 #function to fetch folder information function APP-Parameters($appfolder) { Write-Output $appfolder $data = $appfolder

在控制台中将$Vendor作为创建文件夹的参数传递时,无法识别该$Vendor。它提供的错误字符串输入格式不正确。如果手动传递任何字符串,它将识别并创建具有该名称的文件夹。我尝试将$Vendor解析为字符串。您能帮助我吗

    #function to fetch folder information
    function APP-Parameters($appfolder)
    {
    Write-Output $appfolder

    $data = $appfolder.split("-")
    $APPLICATIONNAME = $data[2]+$data[3]+$data[4]+$data[5]+$data[6]+$data[0]
    $DEPLOYMENTTYPENAME = $data[5]+$data[6]+$data[0]
    $obj= new-object psobject
    $obj | Add-Member Noteproperty APPID $data[0]
    $obj | Add-Member Noteproperty APPNAME $data[2]
    $obj | Add-Member Noteproperty VERSION $data[3]
    $obj | Add-Member Noteproperty LANGUAGE $data[4]
    $obj | Add-Member Noteproperty VARIANT $data[5]
    $obj | Add-Member Noteproperty RELEASEVERSION $data[6]
    #$obj | Add-Member Noteproperty APPLICATIONNAME $APPLICATIONNAME
    #$obj | Add-Member Noteproperty DEPLOYMENTTYPENAME $DEPLOYMENTTYPENAME



    switch ($data[1])
    {
    "MS" 
    {
    $obj | Add-Member Noteproperty VENDOR "Microsoft"
    break
    }
    default {
    $obj | Add-Member Noteproperty VENDOR $data[1]
    }

    }

    Return $obj


    }
    #Function for Creating the Folder
    Function New-CMFolder
    {
        [CmdLetBinding()]
        Param(
        [Parameter(Mandatory=$True,HelpMessage="Please Enter Site Server Site code")]
                  $SiteCode,
        [Parameter(Mandatory=$True,HelpMessage="Please Enter Site Server Name")]
                  $SiteServer,
        [Parameter(Mandatory=$True,HelpMessage="Please Enter Folder Name")]
                  $Name,
        [Parameter(Mandatory=$True,HelpMessage="Please Enter Folder Object Type")]
                  $ObjectType,
        [Parameter(Mandatory=$True,HelpMessage="Please Enter parent folder ID")]
                  $ParentContainerNodeId                                          
             )

        $Arguments = @{Name = $Name; ObjectType = "$ObjectType"; ParentContainerNodeId = "$ParentContainerNodeId"}
        Try{
            Set-WmiInstance -Namespace "root\sms\Site_$SiteCode" -Class "SMS_ObjectContainerNode" -Arguments $Arguments `
            -ComputerName $SiteServer -ErrorAction STOP
        }
        Catch{
            $_.Exception.Message
            "THE VENDOR FOLDER PRESENT" + $Name | out-file  C:\Windows\Logs\test.txt -append
        }          
    }
    #Function for Fetching the node
    function Get-ParentNode($ConsoleFolder)
    {
    $Confolder=$ConsoleFolder.split("\")
    $ParentContainerNodeId="0"
    $len=$Confolder.length

    For ($i=0; $i -lt $len; $i++)
    {
    New-CMFolder -SiteCode "PR1" -SiteServer $SiteServer -Name $Confolder[$i] -ObjectType "6000" -ParentContainerNodeId $ParentContainerNodeId
    $Parent_Node=Get-WMIObject -ComputerName $SiteServer -Namespace "root\sms\site_$siteCode" -Query "Select * From SMS_ObjectContainerNode" | Where { ($_.Name -like $Confolder[$i]) -and ($_.ObjectType -like '6000') }
    $ParentContainerNodeId = $Parent_Node.ContainerNodeID
    }
    $len=$len-1
    $Parent_Node=Get-WMIObject -ComputerName $SiteServer -Namespace "root\sms\site_$siteCode" -Query "Select * From SMS_ObjectContainerNode" | Where { ($_.Name -like $Confolder[$len]) -and ($_.ObjectType -like '6000') }
    $ParentContainerNodeId1 = $Parent_Node.ContainerNodeID
    $obj= new-object psobject
    $obj | Add-Member Noteproperty ParentContainerNodeId $ParentContainerNodeId1
    Return $obj
    }
    #Global Variable Declaration
    $SiteCode="PR1"
    $SiteServer="Babusccmlab1"
    $ObjectType="6000"
    $ConsoleFolder="Global Package\SRT-Packages"
    $ExportFilesLocation="\\babusccmlab1\c$\AZTESTPACKAGES\*.*"
    $ParentContainerNodeId="0"
    $Parent_Node=Get-ParentNode($ConsoleFolder)
    $Parent_Node=$Parent_Node.ParentContainerNodeID

    $ProductionServer="\\SMSSITESERVER\AZTESTPACKAGES\"
    Set-Location C:\
    $a= Get-Childitem  -path $ExportFilesLocation  -include *.zip 
    cd "Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin"
    $Setsite = $SiteCode + ":"
    CD $Setsite


    foreach($x in $a)  {
    If($x.name -match "^[0-9]{6}\-[a-z0-9-_+']*\-[a-z0-9-_+']*\-[a-z0-9.-_+']*\-[a-z0-9-_+']*\-[a-z0-9-_+']*\-[a-z0-9-_+']*\.ZIP")
    {
    $appfoldername = $x.name.TrimEnd(".zip")
    $APPID=APP-Parameters($appfoldername) | SELECT APPID | out-file  C:\Windows\Logs\test.txt -append
    $VENDOR=APP-Parameters($appfoldername)  
    [String]$VENDOR = $VENDOR.Vendor | out-file  C:\Windows\Logs\test.txt -append
    [String]$u = $Vendor  | out-file  C:\Windows\Logs\test.txt -append 
    $APPNAME=APP-Parameters($appfoldername) | SELECT APPNAME | out-file  C:\Windows\Logs\test.txt -append
    $LANGUAGE=APP-Parameters($appfoldername) | SELECT LANGUAGE | out-file  C:\Windows\Logs\test.txt -append
    $VARIANT=APP-Parameters($appfoldername) | SELECT VARIANT | out-file  C:\Windows\Logs\test.txt -append
    $SCCM_APPNAME=APP-Parameters($appfoldername) | SELECT APPLICATIONNAME | out-file  C:\Windows\Logs\test.txt -append
    #$SCCM_DEPLOYMENTTYPENAME=APP-Parameters($appfoldername) | SELECT DEPLOYMENTTYPENAME
    #$RELEASEVERSION=APP-Parameters($appfoldername) | SELECT RELEASEVERSION

     "--------" + $x.name + "--------" | out-file  C:\Windows\Logs\test.txt -append
     "" | out-file  C:\Windows\Logs\test.txt -append


    "THE FOLDER STRUCTURE  MATCH" | out-file  C:\Windows\Logs\test.txt -append
     "" | out-file  C:\Windows\Logs\test.txt -append 
     "" | out-file  C:\Windows\Logs\test.txt -append 
    #----------------------------------------------------SCCM2012 CONSOLE MANAGEMENT---------------------------------------------------------
    New-CMFolder -SiteCode $SiteCode -SiteServer $SiteServer -Name $Vendor -ObjectType $ObjectType -ParentContainerNodeId $Parent_Node


    } else
    {
     "--------" + $x.name + "--------" | out-file   C:\Windows\Logs\test.txt -append
     "" | out-file  C:\Windows\Logs\test.txt -append


    "THE FOLDER STRUCTURE DOES NOT MATCH" | out-file  C:\Windows\Logs\test.txt -append
     "" | out-file  C:\Windows\Logs\test.txt -append 
     "" | out-file  C:\Windows\Logs\test.txt -append
    }
    }

这是哪一行给你的错误

这一行:

[String]$VENDOR = $VENDOR.Vendor | out-file  C:\Windows\Logs\test.txt -append

没有任何意义。管道操作不会返回任何内容,因此$VENDOR将为null。

谢谢,但如果我在管道符号后面的代码中看到这个文件test.txt,我会发现$VENDOR具有值。知道$VENDOR为什么会包含空值会很好。在那一行之后立即输出$VENDOR,看看值是什么。我找到了答案&这是我的错误。我使用$VENDOR作为stroe输出的变量,但是我忘记了$VENDOR已经是在这一行上面定义的对象了。所以我将对象转换为字符串,并在其中赋值。我刚更改了这个变量名,问题就解决了。。。无论如何,非常感谢您的帮助和快速响应