使用Move-ADObject到组织单位时收到错误

时间:2019-05-30 20:43:49

标签: powershell active-directory

尝试将用户移至其他ou,但出现错误。我尝试在网上寻找解决方案,但没有骰子

import pygame
from pygame.locals import *
import math
import random

pygame.init()

triangle1 = pygame.image.load("resources/images/triangle1.png")
triangle2 = pygame.image.load("resources/images/triangle2.png")
square = pygame.image.load("resources/images/square.png")

sky = pygame.image.load("resources/images/sky.png")  
explosion = pygame.mixer.Sound("resources/audio/explosion.wav")
missle = pygame.mixer.Sound("resources/audio/missle.wav")
fire = pygame.mixer.Sound("resources/audio/fire.wav")
move = pygame.mixer.Sound("resources/audio/move.wav")

explosion.set_volume(0.05)
missle.set_volume(0.05)
fire.set_volume(0.05)
move.set_volume(0.05)

pygame.mixer.music.load('resources/audio/warmusic.wav')
pygame.mixer.music.play(-1, 0.0)
pygame.mixer.music.set_volume(0.02)    

width = 640 
height = 480
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("2 Player Tanks")

white = (255,255,255)
black = (0,0,0)
red = (255,0,0)

def background():

    screen.fill(white)

    screen.blit(sky,(0,0))

    backgroundspawn = [0,160,320,480]
    randomspawn = random.choice(backgroundspawn)
    screen.blit(square,(randomspawn,393))
    index = backgroundspawn.index(randomspawn)
    backgroundspawn.pop(index)

    randomspawn = random.choice(backgroundspawn)
    screen.blit(triangle1,(randomspawn,170))
    index = backgroundspawn.index(randomspawn)
    backgroundspawn.pop(index)

    randomspawn = random.choice(backgroundspawn)
    screen.blit(triangle2,(randomspawn,170))
    index = backgroundspawn.index(randomspawn)
    backgroundspawn.pop(index)

    randomspawn = random.choice(backgroundspawn) 
    screen.blit(square,(randomspawn,393))
    index = backgroundspawn.index(randomspawn)
    backgroundspawn.pop(index)

background_surface = pygame.Surface((width, height))

time = pygame.time.get_ticks()

global tankx, tanky, tankmove

tankx = 100
tanky = 100    
tankmove = 1

tankwidth = 40
tankheight = 20
turretwidth = 5 
wheelwidth = 5

background()

def gameloop():
    def tank(x,y,turretpos):
        x = int(x)
        y = int(y)
        possibleturret = [(x-27, y-2), (x-26, y-5), (x-25, y-8), (x-23, y-12), (x-20, y-14),
                  (x-18, y-15), (x-13, y-11)]

        pygame.draw.circle(screen,black,(x,y),10)
        pygame.draw.rect(screen,black,(x-tankheight,y,tankwidth,tankheight))
        pygame.draw.line(screen,black,(x,y),possibleturret[turretpos], turretwidth)

        startx = 15
        for i in range(7):
            pygame.draw.circle(screen,black,(x-startx,y+20),wheelwidth)
            startx -= 5

    keys= pygame.key.get_pressed()

    currentturretpos = 0
    changeturret = 0

    if keys[pygame.K_a]:
        tankx -= tankmove
    if keys[pygame.K_d]:
        tankx += tankmove
    if keys[pygame.K_w]:
        changeturret = 1
    if keys[pygame.K_s]:
        changeturret = -1

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_a or event.key == pygame.K_d:
                tankmove = 0
            if event.key == pygame.K_w or event.key == pygame.K_s:
                changeturret = 0

    screen.blit(background_surface, (0,0))
    currentturretpos += changeturret
    tank(tankx,tanky,currentturretpos)
    pygame.display.update()

run = True
while run:
    gameloop()

我收到的错误是:

  

Move-ADObject:无法验证参数“ Identity”上的参数。参数为空。为参数提供有效值,然后尝试再次运行命令。

1 个答案:

答案 0 :(得分:0)

As Lotpings explains, you need to first get the user object from AD by means of the (string) value that was entered using the Read-Host cmdlet.

Make sure you ask for the SamAccountName of the user, because that is what you will need to find the AD user object.

Import-Module ActiveDirectory

$accountName = Read-Host "Enter the SamAccountName of the terminated user: "

# find the user object using the SamAccountName entered

# Get-ADUser takes a DistinghuishedName, a GUID, a SID or SamAccountName as Identity parameter
$user = Get-ADUser -Identity $accountName
if ($user) {
    # Move-ADObject takes a DistinghuishedName or GUID as Identity parameter
    Move-ADObject -Identity $user.DistinguishedName -TargetPath "OU=DisabledAccounts,DC=nfii,DC=com"

    # you can also pipe the object through:
    # $user | Move-ADObject -TargetPath "OU=DisabledAccounts,DC=nfii,DC=com"
}
else {
    Write-Warning "User with SamAccountName '$accountName' not found."
}