Im writing a custom script from start to finish to search for users ,so i can disable and move them. (script is done and working)
What im trying to do now is to create a easy readable log which also has to be used as an easy rollback.
I.ex.:
Get-Aduser -Identity test -properties SamAccountName,MemberOf,GivenName,Surname
This will return something in line of:
DistinguishedName : CN=test,OU=OUy,OU=Lab Accounts,DC=domain,DC=org
Enabled : True
GivenName : test
Name : test
SamAccountName : test
Surname : test
Memberof : {CN=OU,OU=Norway,OU=Lab Accounts,DC=Domain,DC=org, CN=Domain Admins,CN=Users,DC=Domain,DC=org}
If i use:
$test2 = Get-ADUser -Identity test |
Select-Object -Property SamAccountName,GivenName,Surname,Memberof
which gives me:
SamAccountName GivenName Surname Memberof
-------------- --------- ------- --------
test test test {}
What my issue now is how to log this to either a csv/text file which can be easily imported back for rollback.
Im currently using clixml which preserves the export ive done with a hashtable within a hashtable.
like:
$user=@{
@{
Username=$user.samaccountname
Memberof=$user.memberOf
}
}
This allows me to more or less use dot notation to access the information stored for easy rollback, but viewing the file is not that easy readable
Which method do you propose me to use to log the info i need when alot of the info is some kind of collection of items?
I've tried to explore with PSobject but i havent gotten the hang of that yet. Are there any logging method which will output to a easy to read log and easy use for rollback?
If anyone is able to supply an example and also point me to a page to further explore this i will appreciate it very much.
By readerfriendly im thinking of something like this:
Username,Givenname,Surname,Memberof
Test,test2,test3,Admins;somegroup;somegroup
or
Username,Givenname,Surname,Memberof
Test,test2,test3,Admins somegroup somegroup
EDIT 1 Here is the code that gets the info:
Get-ADUser -Identity test -Properties SamAccountName,GivenName,Surname,Memberof |
Select-Object -Property SamAccountName,GivenName,Surname,Memberof | export-csv C:\test.txt
This is what is in the file as output:
#TYPE Selected.Microsoft.ActiveDirectory.Management.ADUser
"SamAccountName","GivenName","Surname","Memberof"
"test","Mari","Hopkins","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection"