将结果写入文件而不是写入Active Directory实时环境

时间:2016-09-30 12:57:59

标签: powershell logging export-to-csv

我需要在生产环境中实际运行之前输出此脚本将执行的操作。有人可以帮忙吗?

它所做的只是更新用户对象中的EmployeeID属性。我的经理想要了解所有3500名员工在AD中获得的价值,而不是实际写入。我希望这是有道理的。

我的CSV文件:

    package com.sezin.controller;

import com.sezin.model.Book;
import com.sezin.repository.BookRepository;
import com.sezin.repository.UserAccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by sezin on 3/23/16.
 */
@RestController
@RequestMapping("/api/books")
public class BookRestController {

    @Autowired
    BookRepository repository;

    @Autowired
    UserAccountRepository userAccountRepository;

    @RequestMapping(method = RequestMethod.GET)
    public List<Book> getAllBooks(){
        return repository.findAll();
    }

    @RequestMapping(value = "/getByTitle/{title}", method = RequestMethod.GET)
    public Book getBookByTitle(@PathVariable String title){
        return repository.findByTitle(title);
    }

    @RequestMapping(value = "/getByAuthor/{author}", method = RequestMethod.GET)
    public List<Book> getBooksByAuthor(@PathVariable String author){
        return repository.findByAuthor(author);
    }

    @RequestMapping(value ="/getAll/{userName}", method = RequestMethod.GET)
    public List<Book> getBooksByUserName(@PathVariable String userName){
        return repository.findByUserName(userName);
    }




    @RequestMapping(value ="/add", method = RequestMethod.POST)
    public @ResponseBody Book create(@RequestBody Book book){
        if( userAccountRepository.findByUsername(book.getUserName()) != null &&
                repository.findByTitle(book.getTitle()) == null){
            return repository.save(book);
        }
        else
            return null;

    }

    @RequestMapping(value="/delete/{id}", method = RequestMethod.GET)
    public void delete(@PathVariable String id){
        System.out.println("id :: "+id);

        Book book = repository.findById(id);

        if(book != null)
            repository.delete(book);
        else
            System.out.println("Book not exist ");
    }

    @RequestMapping(method = RequestMethod.PUT, value = "{id}")
    public Book update(@PathVariable String id, @RequestBody Book book){
        Book updated = repository.findOne(id);
        updated.setAuthor(book.getAuthor());
        updated.setTitle(book.getTitle());
        updated.setYear(book.getyear());
        return repository.save(book);

    }
}

脚本:

employeeid,Name
9089809890,ktest

1 个答案:

答案 0 :(得分:1)

您可以使用-whatif cmdlet上的Set-AdUser标记以及脚本:

$stuff = Import-Csv c:\temp\finalexport_test.txt
$stuff

$empid = $stuff.employeeid
$userid = $stuff.name

foreach ($user in $userid) {
    Start-Transcript 'yourFile'
    Set-ADUser -Identity $user -EmployeeID $empid -whatif
    Stop-Transcript
    }