当将$ Vendor作为参数传递给控制台创建文件夹时,无法识别$ Vendor。它给错误字符串输入的格式不正确。如果我手动传递任何字符串,它会识别并创建具有该名称的文件夹。我尝试解析$ Vendor to string。你能帮帮我吗?
#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
}
}
答案 0 :(得分:1)
它给你的错误是哪一行?
这一行:
[String]$VENDOR = $VENDOR.Vendor | out-file C:\Windows\Logs\test.txt -append
没有任何意义。该管道操作不会返回任何内容,因此$ VENDOR将为null。