Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Getting AD Users and deleting their Profiles

$
0
0

Hi,

 

i´m fairly new to scripting and especially new to powershell. i will attend a powershell training in a month but i want to play around a bit on my own ;)'

so i have a script which generates AD Users from a .csv file. this works.

the next thing i tried was getting the profile path of all users in a given OU and pipe it through to delete them:



 $FoldersToDelete = Get-ADUser -Filter * -SearchBase "OU=Testschüler,DC=mdz,DC=local" -Properties profilepath | Format-Table -HideTableHeaders profilepath

foreach ($Folder in $FoldersToDelete)

{Remove-Item -path $Folder}

there seems to be a problem with the contents of the variable $Folder because i get the following error:

Remove-Item : Der Pfad "C:\Users\Administrator\Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData" kann nicht gefunden werden, da er nicht vorhanden ist.

In Zeile:5 Zeichen:2

+ {Remove-Item -path $Folder}

+  ~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (C:\Users\Admini...FormatEntryData:String) [Remove-Item], ItemNotFoundException

    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand 

 

the correct path should be C:\Profiles\%USERNAME%
which i get with

Get-ADUser -Filter * -SearchBase "OU=Testschüler,DC=mdz,DC=local" -Properties profilepath | Format-Table -HideTableHeaders profilepath

 

you will probably see that i am a total noob but maybe there is help ;)

thx in advance and best regards


Viewing all articles
Browse latest Browse all 8411

Latest Images

Trending Articles



Latest Images