2017-11-06 6 views
0

現在、VBで問題を解決しようとしていますが、レンガの壁に当たっています。私は多くのコーダーではなく、いつものように基本を理解していますが、この段階で私の仕事は進んでいます。csvに基づいてフォルダを削除する

基本的に私はADから取られたcsv内に存在するログイン名に基づいて2つの特定の場所に存在するフォルダ(すべてのフォルダとファイルが含まれています)を削除したいと思います。

現在のスクリプトでは、90日後にユーザーアカウントが無効になり、一部のグループが削除され、無効になったOUにユーザーアカウントが移動されます。また、CSVに含まれているログイン名と一致するユーザープロファイルとリダイレクトされたフォルダも削除する必要があります。

私がこれまでに以下の組み立てました

'Open up the text file 
Dim oFSO, oTS 
Set oFSO = CreateObject("Scripting.FileSystemObject") 
Set oTS = oFSO.OpenTextFile("c:\scripts\GmailDisabled.csv 

'Assumes the CSV files first row will be the column names and they will be User Name, Email Address, Date Account Expired, Original OU (currently missing login name) 

'Creates the variables 
Dim sLoginName 

'Skip the first line in the code 
Dim sLine, sData 
sLine - oTS.ReadLine 

'Go through file one line at a time 
Do Until oTS.AtEndOfStream 

'Get the user information from this row 
sLoginName - sData(0) 

CSVには、以下の情報を持っています

ユーザー名、ログイン名、メールアドレス、日付のアカウントの有効期限が切れ、オリジナルOU

パスは次のとおりです。

私はIDがPowershellにもっと運があると思いますが、 llyはVBである必要があります。何かが削除されるたびにCSVを更新することも役立ちます。

を見て、あなたが ダン

+0

あなたは私たちにサンプルCSVファイルを表示することができますか?これはvb.netではなくvb6と思われます。 – derloopkat

+0

csvからの行は、この薄暗いcsvValues()のようにstring = sline.split( "、")として簡単に読み取ることができます。私に30分を与えてください。私が戻ってきたら、 – Chillzy

+0

という答えをあなたにもお届けします。ディレクトリ内の私のループを見れば、特定のファイルを見つけることができます: - https://stackoverflow.com/questions/42826832/search-files-basedユーザーが入力したコンソールアプリケーションの日付変更された日付 - v/42832771#42832771 –

答えて

0
'Assumes the CSV files first row will be the column names and they will be User Name, Email Address, Date Account Expired, Original OU (currently missing login name) 

を提供することができる任意のヘルプ「のtest.CSV」 ログイン名、ユーザー名、電子メールアドレス、日付のアカウントの有効期限が切れ、オリジナルOU Daniel.Gangeを持ってくれてありがとう、Daniel Gange、[email protected]、09/08/2017、 "CN = Daniel Gange、OU =テスト、OU =テスト、DC =テスト、DC = co、DC = uk"

Using sr As StreamReader = File.OpenText("c:\scripts\GmailDisabled.csv") 
     sr.ReadLine() 'read the first line you said to skip 
     Do 
      Dim xData As String = sr.ReadLine() 'read one line at the time 
      Dim csvValue() As String = xData.Split(",") ' split at every comma (csv file) 
      ' the first value always has index 0 which is username 
      Dim sUserName As String = csvValue(0) 
      Dim PathToDelete1 As String = String.Format("\\netapp01fs\profiles\{0}", sUserName) 
      Dim PathToDelete2 As String = String.Format("\\rukredir\\{0}", sUserName) 
      MsgBox(PathToDelete1) 
      MsgBox(PathToDelete2) 
     Loop Until sr.EndOfStream = True 'loop until the end of file 
     sr.Close() 'close the csv 
    End Using 

コードが必要な場合は、このフォルダを使用して実際にフォルダを削除します。データを削除するものをテストするときは、絶対にファイルやフォルダを消去しないでください。あなたは、削除したくないものを削除してしまうかもしれません。

'Assumes the CSV files first row will be the column names and they will be User Name, Email Address, Date Account Expired, Original OU (currently missing login name) 
Using sr As StreamReader = File.OpenText("c:\scripts\GmailDisabled.csv") 
    sr.ReadLine() 'read the first line you said to skip 
    Do 
     Dim xData As String = sr.ReadLine() 'read one line at the time 
     Dim csvValue() As String = xData.Split(",") ' split at every comma (csv file) 
     ' the first value always has index 0 which is username 
     Dim sUserName As String = csvValue(0) 
     Dim PathToDelete1 As String = String.Format("\\netapp01fs\profiles\{0}", sUserName) 
     Dim PathToDelete2 As String = String.Format("\\rukredir\\{0}", sUserName) 
     Directory.Delete(PathToDelete1, True) ' set recursive to True to delete files and sub folders 
     Directory.Delete(PathToDelete2, True) ' set recursive to True to delete files and sub folders 
     'MsgBox(PathToDelete1) 
     'MsgBox(PathToDelete2) 
    Loop Until sr.EndOfStream = True 'loop until the end of file 
    sr.Close() 'close the csv 
End Using 

短いバージョン

'Assumes the CSV files first row will be the column names and they will be User Name, Email Address, Date Account Expired, Original OU (currently missing login name) 
    Using sr As StreamReader = File.OpenText("c:\scripts\GmailDisabled.csv") 
     sr.ReadLine() 'read the first line you said to skip 
     Do 
      Dim xData As String = sr.ReadLine() 'read one line at the time 
      ' the first value always has index 0 which is username 
      Directory.Delete(String.Format("\\netapp01fs\profiles\{0}", xData.Split(",")(0)), True) ' set recursive to True to delete files and sub folders 
      Directory.Delete(String.Format("\\rukredir\\{0}", xData.Split(",")(0)), True) ' set recursive to True to delete files and sub folders 
     Loop Until sr.EndOfStream = True 'loop until the end of file 
     sr.Close() 'close the csv 
    End Using 
+0

John Smith、John.Smith @ dfdsgdsgsdgsdfdsf、08/08/2017、 "CN = John Smith、OU = Test、DC = Test、DC = co、DC = uk" –

+0

ユーザー名、電子メールアドレス、日付アカウントの期限切れ、元のOU –

+0

現在、エクスポートにはログイン名が含まれていません。後で追加します。 –

関連する問題