我需要使用导入的csv文件从Active Directory中删除用户

时间:2017-06-12 17:31:17

标签: powershell active-directory powershell-v2.0 powershell-v3.0

我有一个包含用户名列表的CSV文件,我需要使用class NotificationService: UNNotificationServiceExtension { var contentHandler: ((UNNotificationContent) -> Void)? var bestAttemptContent: UNMutableNotificationContent? override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { self.contentHandler = contentHandler bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) if let bestAttemptContent = bestAttemptContent { // Setting the category associated with the notification if let category = bestAttemptContent.userInfo["category"] as? String { bestAttemptContent.categoryIdentifier = category } // Fetching luubra if available if let attachmentString = bestAttemptContent.userInfo["image"] as? String, let attachmentUrl = URL(string: attachmentString) { let session = URLSession(configuration: URLSessionConfiguration.default) let attachmentDownloadTask = session.downloadTask(with: attachmentUrl, completionHandler: { url, _, error in if let error = error { print("Error downloading notification image: \(error)") } else if let url = url { do { let attachment = try UNNotificationAttachment(identifier: attachmentString, url: url, options: [UNNotificationAttachmentOptionsTypeHintKey: kUTTypeJPEG]) bestAttemptContent.attachments = [attachment] } catch let e { print("Error creating NotificationAttachment: \(e)") } } print("Remote notification content: \(bestAttemptContent)") contentHandler(bestAttemptContent) }) attachmentDownloadTask.resume() } } } override func serviceExtensionTimeWillExpire() { // Called just before the extension will be terminated by the system. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { contentHandler(bestAttemptContent) } } } 从Active Directory中删除所有这些用户。我对这个命令的语法不太熟悉 - 希望你们能在这里帮助我。

Remove-ADObject command

1 个答案:

答案 0 :(得分:5)

您必须对Remove-ADObject使用DN或GUID。你可以这样做:

Import-Module ActiveDirectory

$list = Import-CSV C:\Users\user\Desktop\deleteuserstest.csv

forEach ($item in $list) {
    $samAccountName = $item.samAccountName

    #Get DistinguishedName from SamAccountName
    $DN = Get-ADuser -Identity $Samaccountname -Properties DistinguishedName |
        Select-Object -ExpandProperty DistinguishedName

    #Remove object using DN
    Remove-ADObject -Identity $DN
}