LeVeilleur.net

Subscribe

Archive for the ‘powershell’

VI Toolkit / PowerShell : How to connect to more than one Virtual Center

mars 08, 2010 By: Christopher Keyaert Category: powershell No Comments →

Hello All,

First thing, the documentation on VI Toolkit :

http://communities.vmware.com/docs/DOC-4210

If you want to connect to more than one virtual center at the same time, here the starting code :

1
2
3
4
5
6
7
$vcs = @()
$vcs += connect-viserver <vc 1>
$vcs += connect-viserver </vc><vc 2>
# You could add many as you need...

# Command example : Snapshot all VMs across all VirtualCenter servers.
get-vm -server $vcs | new-snapshot

Be carrefull, the command GET-VM $VCS will not return the same values than GET-VM.
If you use GET-VM, you will receive the VM List only for the Virtucal Center that you connect last. If you want the get all the VM of your different virutal centers, you absolutly need to add the parameter -server $vcs to you command. In a general way, don’t forget to add -server $vcs to every command than you use with the VI Toolkit.

SCOM / PowerShell : Number of locked AD accounts

mars 08, 2010 By: Christopher Keyaert Category: Scom 2007, powershell No Comments →

Dear All,

Here a new little powershell script that creates an event 6970 in the event viewer when there is more than X accounts locked in less than Y minutes. Now, you just have to create a new rule in SCOM that collect event with the ID6970 and schedule that script to run every 10 minutes.

Thanks to that you can be alert when there is an attack attempt to your Active Directory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
########################################################
#Get the number of lock account in less than 10 minutes
########################################################
###########################
# Param
###########################
$LockedSince = 10 #Minutes
$NumberofLockedAccount = 50 #

###########################
# FUNCTIONS
###########################
###########################
# SCRIPT
###########################
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = "(&amp;(objectClass=User)(lockoutTime&gt;=1))"
$colProplist = "name","samaccountname","lockoutTime"

foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i) | out-null}
$colResults = $objSearcher.FindAll()

$cpt = 0
$result = $null
$result2 = $null

foreach ($objResult in $colResults) {

    $domainname = $objDomain.name
    $samaccountname = $objResult.Properties.samaccountname

    $user = [ADSI]"WinNT://$domainname/$samaccountname"
    $ADS_UF_LOCKOUT = 0x00000010
    #$objResult.Properties

    if(($user.UserFlags.Value -band $ADS_UF_LOCKOUT) -eq $ADS_UF_LOCKOUT) {
        $Sam = $objResult.Properties.samaccountname
        $Name = $objResult.Properties.name
        [String]$LockTime = $objResult.Properties.lockouttime
        [datetime] $LockTime = [datetime]::FromFileTime($LockTime)

        #We want all the account locked in the last 24h
        $DayDate = Get-Date
        $DayDateBefore = $DayDate.AddMinutes(-$LockedSince)

        if(($LockTime -gt $DayDateBefore) -and ($LockTime -lt  $DayDate))
            {
            Write-Host "************"
            Write-Host "User : $sam"
            Write-Host "Name : $name"
            Write-Host "LockTime : $lockTime"
            Write-Host "************"
            Write-Host ""

            $result2 += "************`r"
            $result2 += "User : $sam`r"
            $result2 += "Name : $name`r"
            $result2 += "LockTime : $lockTime`r"
            $result2 += "************`r"
            $result2 += "`r"

            $cpt += 1
            }
    }
}

Write-Host "************"
Write-Host "There is $cpt account(s) locked in the last $LockedSince minutes"
Write-Host "************"

$result += "************`r"
$result += "There is $cpt account(s) locked in the last $LockedSince minutes`r"
$result += "************`r"
$result += $result2

if($cpt -ge $NumberofLockedAccount)
    {
    Write-Host ""
    Write-Host "Limit reached, /!\ ALERT /!\"
    Write-Host ""
    $infoevent=[System.Diagnostics.EventLogEntryType]::Error
    }
else{
    $infoevent=[System.Diagnostics.EventLogEntryType]::Information
    }  

############################
#Var for the event creation
############################
$evt = new-object System.Diagnostics.EventLog("Application")
$evt.Source = "AD-SCOM"
$evt.MachineName = "."
$evt.WriteEntry($result,$infoevent,6970)

OpsMgr / SCOM : Automatic Agent Deployment With PowerShell

janvier 20, 2010 By: Christopher Keyaert Category: Scom 2007, powershell No Comments →

Hello everyone,

Some weeks ago, I had to deploy SCOM Agent on more than 350 windows servers at the time. For that, I wrote a PowerShell Script where you just have to give a server list in input and the name of your RMS/MS . And that’s it, the script is performing the agent installation for you. A CSV file will be generated as output with the agent installation status of each servers.

Concerning the right management, you have to ensure that the Default Action Account using on the server that you will use for deploying the agents (MS normally), has administrative right on the servers that you want to add in SCOM. For that, and the duration of the deployment only, use a Domain Admin Account as the Run As Account of your MS/RMS.

The script :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
###########################
# Autor : Christopher Keyaert
# Version : 1.0
# Date : 28 DEC 2009
##########################
#Getting the credential of the user
#$creds = Get-Credential

###########################
#Param
##########################
$RMS =  #don't forget to use the FQN RMS001.contoso.local
$MS  =  #don't forget to use the FQN MS001.contoso.local

$myFile = "D:\Dep\myfile.txt" #List of Servers
$ResultPath = "D:\Dep" #Folder for path output
Start-Transcript -path "$ResultPath\Transcript$(get-date -uformat '%Y-%m-%d_%Hh%Ms%S').log"

$MaintenanceModeEnable = $false

$MaintenanceModeDuration = 10 * 1440 # 1440 minutes per day
$comment = 'Global Deployment'
$reason = 'PlannedOther'

######################
#Functions
#####################
function SetToMaintenanceMode($rootMS,$computerPrincipalName,$minutes,$comment,$reason)
{
$computerPrincipalName = $computerPrincipalName + ".dir.ucb-group.com"
$computerClass = get-monitoringclass -name:Microsoft.Windows.Computer
$healthServiceClass = get-monitoringclass -name:Microsoft.SystemCenter.HealthService
$healthServiceWatcherClass = get-monitoringclass -name:Microsoft.SystemCenter.HealthServiceWatcher
$computerCriteria = "PrincipalName='" + $computerPrincipalName + "'"
$computer = get-monitoringobject -monitoringclass:$computerClass -criteria:$computerCriteria
$healthServices = $computer.GetRelatedMonitoringObjects($healthServiceClass)
$healthService = $healthServices[0]
$healthServiceCriteria = "HealthServiceName='" + $computerPrincipalName + "'"
$healthServiceWatcher = get-monitoringobject -monitoringclass:$healthServiceWatcherClass -criteria:$healthServiceCriteria
$startTime = [System.DateTime]::Now
$endTime = $startTime.AddMinutes($minutes)

Write-host " "
"Putting " + $computerPrincipalName + " into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$computer -comment:$comment -Reason:$reason
 
"Putting the associated health service into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$healthService -comment:$comment -Reason:$reason
 
"Putting the associated health service watcher into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$healthServiceWatcher -comment:$comment -Reason:$reason
Write-host " "

}

#################################
#Init the connection to SCOM srv
#################################
if(-not (Get-pssnapin | Where-Object {$_.Name -eq "Microsoft.EnterpriseManagement.OperationsManager.Client"}))
    {
    Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client
    }  
new-managementGroupConnection -ConnectionString:$RMS
Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin ;
Set-Location $RMS -ErrorVariable errSnapin ;   

##########################
#Agent installation
##########################
#Creating the computers list
$ComputersList  = @()
$ComputersList = Get-Content $myFile

#Define a WindowsDiscoveryConfiguration
$discoConfig = New-WindowsDiscoveryConfiguration –ComputerName: $ComputersList –PerformVerification: $true -ComputerType: "Server" #–ActionAccountCredential: $creds

#Start the discovery process.
$managementServer = Get-ManagementServer | Where-Object {$_.PrincipalName -like "*$MS*"}

$discoResult = Start-Discovery –ManagementServer: $managementServer –WindowsDiscoveryConfiguration: $discoConfig

#Check that the discovery process discovered the Windows computers you specified.
$discoResult.CustomMonitoringObjects

if($discoResult.CustomMonitoringObjects -ne $null)
    {
    Write-Host "Agent installation in progress..."
    Write-Host ""
    Install-Agent –ManagementServer $managementServer –AgentManagedComputer $discoResult.CustomMonitoringObjects

    Write-host "Installation Finished, waiting for 60 secondes"
    Start-Sleep -s 60
    }
else{
    Write-Host "No servers discovered"
    }  

####################################################################
#We have to check if all the agent has been well installed + Maintenance mode
#####################################################################
Write-Host ""
Write-Host "Installation Checking"
Write-Host ""

$InstallArray = @()
foreach($srv in $ComputersList)
    {
    $Value = $null
    $Value = Get-agent | Where-Object {$_.ComputerName -like "*$srv*"}
   
    if($Value -ne $null)
        {
        Write-Host "$srv - Agent installed "
        $InstallTime = $Value.InstallTime
        $HealthState = $Value.HealthState
        $AgentInstalled = $true
       
        #Write-Host "Activation of the Maintenance Mode"
        #Put the server in Maintenance Mode
        if($MaintenanceModeEnable -eq $true){SetToMaintenanceMode $RMS $srv $MaintenanceModeDuration $comment $reason}
       
        }
    else{
        Write-Host "$srv - Agent not installed"
        $AgentInstalled = $false
        $InstallTime = ""
        $HealthState = ""
        }
   
    $obj = New-Object PSObject
    $obj | Add-Member Noteproperty -Name "Name" -Value $srv
    $obj | Add-Member Noteproperty -Name "AgentInstall" -Value  $AgentInstalled
    $obj | Add-Member Noteproperty -Name "InstallTime" -Value  $InstallTime
    $obj | Add-Member Noteproperty -Name "HealthState" -Value  $HealthState
    $InstallArray += $obj
    }

Write-Host ""  
Write-Host "Save the Result File"  

$InstallArray  | Export-Csv "$ResultPath\$(get-date -uformat '%Y-%m-%d_%Hh%Ms%S').csv"
Stop-Transcript

PowerShell : Upload file to WebDav Server

août 14, 2009 By: Christopher Keyaert Category: powershell 2 Comments →

A new PowerShell for upload one file to a WebDav Server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
########################################
#Webdav Access with PowerShell
########################################

#Put the complete path of your file
$file = "D:\test.txt"

#Put the url without the last "/"
$url  = "http://mywebSite/webdav"  

#Provide User and Pwd for Webdav Access
$user = "user"
$pass = "pwd"

########################################
#Script
#######################################

#Adding the name of the file at the end of the URL
$url += "/" + $file.split('\')[(($file.split("\")).count - 1)]

#Connecting to WebDav
Write-Host "File upload started"

# Set binary file type
Set-Variable -name adFileTypeBinary -value 1 -option Constant

$objADOStream = New-Object -ComObject ADODB.Stream
$objADOStream.Open()
$objADOStream.Type = $adFileTypeBinary
$objADOStream.LoadFromFile("$file")
$arrbuffer = $objADOStream.Read()

$objXMLHTTP = New-Object -ComObject MSXML2.ServerXMLHTTP
$objXMLHTTP.Open("PUT", $url, $False, $user, $pass)
$objXMLHTTP.send($arrbuffer)

Write-Host "File upload finished"

PowerShell : Users, Groups, Services, Shares

avril 16, 2009 By: Christopher Keyaert Category: Windows, powershell No Comments →

Hello tout monde,

Voici un nouveau script permettant de récupérer :

-Local Users
-Local Groups
-Local Services
-Shares (With Shares Permissions and Ntfs Security)
-Testing the existing of a particular reg Key

Bonne journée

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
########################
#Functions
########################
$arrExclude = "NT AUTHORITY\LocalService",
            "NT AUTHORITY\Local Service",
            "NT AUTHORITY\NETWORK SERVICE",
            "NT AUTHORITY\NetworkService",
            "LocalSystem",
            ".\ASPNET"

function checkExclusions([string]$strval)
    {
    foreach ($val in $arrExclude)
        {if ($val.ToLower() -eq $strval){return $true}  }
    return $false
    }

function Get-MySharePermissions
{
    param([string]$computername,[string]$sharename)
    $ShareSec = Get-WmiObject -Class Win32_LogicalShareSecuritySetting -ComputerName $computername
    ForEach ($ShareS in ($ShareSec | Where {$_.Name -eq $sharename}))
    {
        $SecurityDescriptor = $ShareS.GetSecurityDescriptor()
        $myCol = @()
        ForEach ($DACL in $SecurityDescriptor.Descriptor.DACL)
        {
            $myObj = "" | Select Domain, ID, AccessMask, AceType
            $myObj.Domain = $DACL.Trustee.Domain
            $myObj.ID = $DACL.Trustee.Name
            Switch ($DACL.AccessMask)
            {
                2032127 {$AccessMask = "FullControl"}
                1179785 {$AccessMask = "Read"}
                1180063 {$AccessMask = "Read, Write"}
                1179817 {$AccessMask = "ReadAndExecute"}
                -1610612736 {$AccessMask = "ReadAndExecuteExtended"}
                1245631 {$AccessMask = "ReadAndExecute, Modify, Write"}
                1180095 {$AccessMask = "ReadAndExecute, Write"}
                268435456 {$AccessMask = "FullControl (Sub Only)"}
                default {$AccessMask = $DACL.AccessMask}
            }
            $myObj.AccessMask = $AccessMask
            Switch ($DACL.AceType)
            {
                0 {$AceType = "Allow"}
                1 {$AceType = "Deny"}
                2 {$AceType = "Audit"}
            }
            $myObj.AceType = $AceType
            Clear-Variable AccessMask -ErrorAction SilentlyContinue
            Clear-Variable AceType -ErrorAction SilentlyContinue
            $myCol += $myObj
        }
    }
    Return $myCol
}

function Ping (  [string] $strComputer )
{
  $timeout=120;
  trap { continue; }

  $ping = new-object System.Net.NetworkInformation.Ping
  $reply = new-object System.Net.NetworkInformation.PingReply

  $reply = $ping.Send($strComputer, $timeout);
  if( $reply.Status -eq "Success"  )
  {
     return $true;
  }
  return $false;
}

########################
#Script
########################
$pathFolder = "D:\Reporting\ComputerPerm"
$computersList = get-content "$pathFolder\list.txt"
$ArrayUser = @()
$ArrayGroup = @()
$ArrayKey = @()
$ArrayService = @()
$ArrayShare = @()
$ArrayAccess = @()

foreach($computer in $computersList)
{

#################################################################################################
$retPing = Ping $computer
if($retPing -eq $true)
    {
    #Disabling the error on the screen
    $errorActionPreference="SilentlyContinue"
    $testAccss = get-wmiobject Win32_OperatingSystem -computername $computer -ErrorVariable ERR
        If($ERR)
            {$Access = $false}
        else{$Access = $true}
    }
else{$Access = $false}

if($Access -eq $false)
    {
    #Srv not ping or denied
    Write-Host "Server : " (($computer).trim()).ToUpper() " - Ping : $retPing - Access : $Access"
    $obj=New-Object PSObject
    $obj | Add-Member Noteproperty -Name "ServerName" -Value (($computer).trim()).ToUpper()
    $obj | Add-Member Noteproperty -Name "PING" -Value $retPing
    $obj | Add-Member Noteproperty -Name "ACCESS" -Value $Access
    $ArrayAccess += $obj
    }
else{
    #Working on it

#################################################################################################
Write-Host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Write-Host ""
Write-host "ServerName : $computer"
Write-Host ""

#################################################################################################
Write-Host "***********************"
Write-Host "List local user account"
Write-Host "***********************"
Write-Host ""

$namespace = "root\CIMV2"
$usersList = Get-WmiObject -class Win32_UserAccount -computername $computer -namespace $namespace -filter "localaccount=true"

foreach($user in $usersList)
    {
    Write-host "Account Name : " $user.name
    Write-Host "Account Description : " $user.description
    Write-host "Disabled : " $user.disabled
    Write-Host ""

    $obj=New-Object PSObject
    $obj | Add-Member Noteproperty -Name "ServerName" -Value (($computer).trim()).ToUpper()
    $obj | Add-Member Noteproperty -Name "AccountName" -Value (($user.name).trim()).ToUpper()
    $obj | Add-Member Noteproperty -Name "AccountDescription" -Value (($user.description).trim()).ToUpper()
    $obj | Add-Member Noteproperty -Name "Disabled" -Value $user.disabled
    $ArrayUser += $obj
    }

#################################################################################################
Write-Host "***********************"
Write-Host "List local Group"
Write-Host "***********************"
Write-Host ""

$results = Get-WmiObject -class Win32_Group -computername $computer -namespace $namespace -filter "localaccount=true"
foreach($result in $results)
    {
    Write-Host "Group Name : " $result.name
    Write-Host "Group Description : " $result.description
    Write-Host ""

    $GroupName = $result.name
    $group =[ADSI]"WinNT://./$GroupName"
    $members = @($group.psbase.Invoke("Members"))
    $list = $members | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
    if($list -ne $null)
        {
        foreach($member in $list)
            {
            Write-host "Account Name : " $member.toupper()

            $obj=New-Object PSObject
            $obj | Add-Member Noteproperty -Name "ServerName" -Value (($computer).trim()).ToUpper()
            $obj | Add-Member Noteproperty -Name "GroupName" -Value (($result.name).trim()).ToUpper()
            $obj | Add-Member Noteproperty -Name "GroupDescription" -Value (($result.description).trim()).ToUpper()
            $obj | Add-Member Noteproperty -Name "Member" -Value (($member).trim()).ToUpper()
            $ArrayGroup += $obj
            }
        }
    else
        {
        $obj=New-Object PSObject
        $obj | Add-Member Noteproperty -Name "ServerName" -Value (($computer).trim()).ToUpper()
        $obj | Add-Member Noteproperty -Name "GroupName" -Value (($result.name).trim()).ToUpper()
        $obj | Add-Member Noteproperty -Name "GroupDescription" -Value (($result.description).trim()).ToUpper()
        $obj | Add-Member Noteproperty -Name "Member" -Value ""
        $ArrayGroup += $obj
        }

    Write-Host ""
    }

#################################################################################################
Write-Host ""
Write-Host "********************"
Write-Host "Testing Registry Key"
Write-Host "********************"
Write-Host ""

#Just for testing purpose
#$key = "SYSTEM\CurrentControlSet\Services\W32Time\Parameters"
$key = "SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\AutoShareServer"
$type = [Microsoft.Win32.RegistryHive]::LocalMachine
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $computer)
$regKey = $regKey.OpenSubKey($key)

Write-Host "Key : $key"
if($regKey -eq $null)
    {Write-Host "Key Present : false";
    $keyVal = $false
    }
else{Write-Host "Key Present : true"
    $keyVal = $true
    }

$obj=New-Object PSObject
$obj | Add-Member Noteproperty -Name "ServerName" -Value (($computer).trim()).ToUpper()
$obj | Add-Member Noteproperty -Name "Key" -Value (($key).trim()).ToUpper()
$obj | Add-Member Noteproperty -Name "KeyVal" -Value $keyVal
$ArrayKey += $obj  

#################################################################################################
Write-Host ""
Write-Host "**************************"
Write-Host "Service with local account"
Write-Host "**************************"
Write-Host ""

$results = gwmi win32_service -computer $Computer -property name, startname, caption
foreach ($result in $results)
    {
    $account = $result.StartName.ToLower()
    if ((checkExclusions $account) -eq $false)
        {
        Write-Host "Service : " $result.Name
        Write-Host "Caption : " $result.Caption
        Write-Host "Account : " $account
        Write-Host ""

        $obj=New-Object PSObject
        $obj | Add-Member Noteproperty -Name "ServerName" -Value (($computer).trim()).ToUpper()
        $obj | Add-Member Noteproperty -Name "Service" -Value (($result.Name).trim()).ToUpper()
        $obj | Add-Member Noteproperty -Name "Caption" -Value $result.Caption
        $obj | Add-Member Noteproperty -Name "Account" -Value $account
        $ArrayService += $obj      

        }
    }

#################################################################################################
Write-Host ""
Write-Host "**************************"
Write-Host "Share on the computer"
Write-Host "**************************"
Write-Host ""
$results = get-WmiObject Win32_Share -computer $Computer
foreach ($result in $results)
    {
    Write-Host ""
    Write-Host "---------------"
    Write-Host ""
    Write-Host "Share Name : " $result.name
    Write-Host "Share Path : " $result.path
    Write-Host "Share Description : " $result.description
    Write-Host
    Write-Host "/!\Share Persmissions /!\"
    $shareInfos = Get-MySharePermissions $Computer $result.name
    $cpt= 1
    foreach($shareInfo in $shareInfos)
        {
        Write-Host "$cpt-Domain : " $shareInfo.domain
        Write-Host "$cpt-User : " $shareInfo.id
        Write-Host "$cpt-AccessMask : " $shareInfo.accessMask
        Write-Host "$cpt-AceType : " $shareInfo.AceType
        Write-Host ""
        Write-Host "/!\Ntfs Persmissions /!\"

        $path = "\\$computer\" + $result.name

        if($result.name -ne "IPC$")
            {
            $values = Get-Acl $path  | select-object path,owner,accesstostring,group
            foreach($value in $values)
                {
                Write-Host $value.path
                Write-Host $value.owner
                Write-Host $value.accesstostring
                Write-Host $value.group
                Write-Host ""

                $obj=New-Object PSObject
                $obj | Add-Member Noteproperty -Name "ServerName" -Value (($computer).trim()).ToUpper()
                $obj | Add-Member Noteproperty -Name "ShareName" -Value (($result.name).trim()).ToUpper()
                $obj | Add-Member Noteproperty -Name "SharePath" -Value (($result.path).trim()).ToUpper()
                $obj | Add-Member Noteproperty -Name "ShareDescription" -Value $result.description
                $obj | Add-Member Noteproperty -Name "Domain" -Value $shareInfo.domain
                $obj | Add-Member Noteproperty -Name "User" -Value $shareInfo.id
                $obj | Add-Member Noteproperty -Name "AccessMask" -Value $shareInfo.accessMask
                $obj | Add-Member Noteproperty -Name "AceType" -Value $shareInfo.AceType
                $obj | Add-Member Noteproperty -Name "NTFSPath" -Value (($value.path).trim()).ToUpper()
                $obj | Add-Member Noteproperty -Name "NTFSOwner" -Value $value.owner
                $obj | Add-Member Noteproperty -Name "NTFSAccesstoString" -Value $value.accesstostring
                $obj | Add-Member Noteproperty -Name "NTFSGroup" -Value $value.group
                $ArrayShare += $obj
                }
            }
        else
            {
            $obj=New-Object PSObject
            $obj | Add-Member Noteproperty -Name "ServerName" -Value (($computer).trim()).ToUpper()
            $obj | Add-Member Noteproperty -Name "ShareName" -Value (($result.name).trim()).ToUpper()
            $obj | Add-Member Noteproperty -Name "SharePath" -Value (($result.path).trim()).ToUpper()
            $obj | Add-Member Noteproperty -Name "ShareDescription" -Value $result.description
            $obj | Add-Member Noteproperty -Name "Domain" -Value $shareInfo.domain
            $obj | Add-Member Noteproperty -Name "User" -Value $shareInfo.id
            $obj | Add-Member Noteproperty -Name "AccessMask" -Value $shareInfo.accessMask
            $obj | Add-Member Noteproperty -Name "AceType" -Value $shareInfo.AceType
            $obj | Add-Member Noteproperty -Name "NTFSPath" -Value ""
            $obj | Add-Member Noteproperty -Name "NTFSOwner" -Value ""
            $obj | Add-Member Noteproperty -Name "NTFSAccesstoString" -Value ""
            $obj | Add-Member Noteproperty -Name "NTFSGroup" -Value ""
            $ArrayShare += $obj
            }

        $cpt+= 1
        }

    }
#################################################################################################

    #End test Access
    }

}

$ArrayUser | Export-Csv "$pathFolder\1-user.csv"
$ArrayGroup | Export-Csv "$pathFolder\2-group.csv"
$ArrayKey | Export-Csv "$pathFolder\3-RegKey.csv"
$ArrayService | Export-Csv "$pathFolder\4-Service.csv"
$ArrayShare | Export-Csv "$pathFolder\5-Share.csv"
$ArrayAccess | Export-Csv "$pathFolder\Access.csv"