powershell PowerShell:SCCM添加到集合

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell PowerShell:SCCM添加到集合相关的知识,希望对你有一定的参考价值。

#Create Collections and Membership Rules from Text Files
#Author: Mike Terrill
#Set path to collection directory
$collectiondir = "D:\Collections\"
 
#Pull only .TXT files into array
$filenames = Get-ChildItem $collectiondir* -include *.txt
 
for ($x=0; $x -lt ($filenames.Length); $x++) {
    $collectionname = $filenames.Name[$x].Split(".")[0]
    $collectionname
    #Add new collection based on the file name
    try {
        New-CMDeviceCollection -Name $collectionname -LimitingCollectionName "All Systems"
        }
    catch {
        "Error creating collection - collection may already exist: $collectionname" | Out-File "$collectiondir\$collectionname`_invalid.log" -Append
        }
 
    #Read list of computers from the text file
    $computers = Get-Content $filenames[$x]
    foreach($computer in $computers) {
        try {
            Add-CMDeviceCollectionDirectMembershipRule  -CollectionName $collectionname -ResourceId $(get-cmdevice -Name $computer).ResourceID
            }
        catch {
            "Invalid client or direct membership rule may already exist: $computer" | Out-File "$collectiondir\$collectionname`_invalid.log" -Append
            }
    }
}

以上是关于powershell PowerShell:SCCM添加到集合的主要内容,如果未能解决你的问题,请参考以下文章

powershell怎么运行

powershell PowerShell:启动PowerShell作为其他用户提升

powershell [提示输入powershell] #powershell #input #prompt

powershell 测量PowerShell命令或PowerShell脚本的速度

powershell远程下载exe并执行

powershell 使用啥端口