This commit is contained in:
2023-07-04 12:59:44 +02:00
parent 2cef42a718
commit 09c2faad93
231 changed files with 261001 additions and 4 deletions

View File

@ -0,0 +1,131 @@
<#
.SYNOPSIS
<Overview of script>
.NOTES
Version : 1.0
Author : Hubert CORNET
Creation Date : <Date>
Purpose/Change : <Initial script development>
.LINK
https://www.tips-of-mine.fr
.EXEMPLE
<Example goes here. Repeat this attribute for more than one example>
.DESCRIPTION
Permet de :
- Renommer le serveur
- Changer la configuration reseau du serveur
- Desactiver la configuration de securite renforer pour IE (admins et/ou les users)
- Desactiver l'ouverture automatique du gestionnaire de serveur au demarrage
Teste sur : Windows Server 2008 R2 / Windows Server 2012 / Windows Server 2012R2 / Windows Server 2016 / Windows Server 2019 / Windows Server 2022
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
<Inputs if any, otherwise state None>
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
#>
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
# Définir l'action d'erreur pour continuer silencieusement
$ErrorActionPreference = "SilentlyContinue"
# Bibliothèques de fonctions requises
#----------------------------------------------------------[Declarations]----------------------------------------------------------
# Version Script
$sScriptVersion = "1.0"
#Log File Info
$sLogPath = "C:\Tmp"
$sLogName = "Configuration-serveur.log"
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
$serverIp = "10.0.4.100"
$serverMask = "255.255.255.0"
$serverInterfaceAlias = "Ethernet0"
$serverDefaultGateway = "10.0.4.1"
$serverDnsServers = "10.0.4.4","10.0.4.2"
$serverName = "SWRDSP01"
$desactivateIeEsc = $true
$ieEscUsers = @("admins", "users") # valeurs possible @("admins"), @("users") ou @("admins", "users")
$doNotOpenServerManagerAtLogon = $false
$JoinDomain = $false
$Domain = "Tips-Of-Mine.local"
$pw = "Password123" | ConvertTo-SecureString -asPlainText Force # Specify the password for the domain admin.
$usr = "$Domain\administrateur" # Specify the domain admin account.
$creds = New-Object System.Management.Automation.PSCredential($usr,$pw)
$RemoteDesktop = $true
#-----------------------------------------------------------[Functions]------------------------------------------------------------
# fonction permettant de renommer le serveur
Function Set-ServerName {
param(
[string]$name
)
Rename-Computer -NewName $name
}
Function Set-ServerIpConfiguration {
param(
[string]$ip,
[string]$mask,
[string]$defaultGateway,
[string]$interfaceAlias,
[string[]]$dnsServers
)
$nicIndex = (Get-WMIObject Win32_NetworkAdapter | where {$_.netconnectionid -eq $interfaceAlias}).InterfaceIndex
$nic = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $nicIndex}
$nic.EnableStatic($ip, $mask)
$nic.SetGateways($defaultGateway)
$nic.SetDNSServerSearchOrder($dnsServers)
}
# fonction permettant de desactiver la securite renforcée pour ie
Function Disable-IeEscForUsers {
param(
[string[]]$users
)
If($ieEscUsers.Contains("admins")) {
$adminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
Set-ItemProperty -Path $adminKey -Name "IsInstalled" -Value 0
}
If($ieEscUsers.Contains("users")) {
$userKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
Set-ItemProperty -Path $userKey -Name "IsInstalled" -Value 0
}
}
# fonction permettant de desactiver l'ouverture automatique au demarrage du gestionnaire de serveur
Function Disable-OpenServerManagerAtLogon {
$serverManagerKey = "HKLM:\SOFTWARE\Microsoft\ServerManager"
Set-ItemProperty -Path $serverManagerKey -Name "DoNotOpenServerManagerAtLogon" -Value 1
}
#------------------------------------------------------------[Script]--------------------------------------------------------------
Set-ServerName -name $serverName
Set-ServerIpConfiguration -ip $serverIp -mask $serverMask -defaultGateway $serverDefaultGateway -interfaceAlias $serverInterfaceAlias -dnsServers $serverDnsServers
If ($desactivateIeEsc -eq $true) { Disable-IeEscForUsers -users $ieEscUsers }
If ($doNotOpenServerManagerAtLogon -eq $true) { Disable-OpenServerManagerAtLogon }
If ($JoinDomain -eq $true) { add-computer domainname $Domain -Credential $creds -restart -force -verbose }
If ($RemoteDesktop -eq $true) {
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\" -Name "fDenyTSConnections" -Value 0
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\" -Name "UserAuthentication" -Value 1
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
}
Restart-Computer

View File

@ -0,0 +1,58 @@
<#
.SYNOPSIS
<Overview of script>
.NOTES
Version : 1.0
Author : Hubert CORNET
Creation Date : <Date>
Purpose/Change : <Initial script development>
.LINK
https://www.tips-of-mine.fr
.EXEMPLE
<Example goes here. Repeat this attribute for more than one example>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
<Inputs if any, otherwise state None>
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
#>
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
# Définir l'action d'erreur pour continuer silencieusement
$ErrorActionPreference = "SilentlyContinue"
# Bibliothèques de fonctions requises
#----------------------------------------------------------[Declarations]----------------------------------------------------------
# Version Script
$sScriptVersion = "1.0"
#Log File Info
$sLogPath = "C:\Tmp"
$sLogName = "Import-Module-Offline.log"
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
Start-Transcript -Path $sLogFile -NoClobber
#-----------------------------------------------------------[Functions]------------------------------------------------------------
#--------------------------------------------------------[Debut Du Script]---------------------------------------------------------
Find-Module Name *ReportHTML*| Select Name, Version, Repository
Save-Module Name ReportHTML Path C:\Automation\
#---------------------------------------------------------[Fin Du Script]----------------------------------------------------------
Stop-Transcript

View File

@ -0,0 +1,76 @@
<#
.SYNOPSIS
<Overview of script>
.NOTES
Version : 1.0
Author : Hubert CORNET
Creation Date : <Date>
Purpose/Change : <Initial script development>
.LINK
https://www.tips-of-mine.fr
.EXEMPLE
<Example goes here. Repeat this attribute for more than one example>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
<Inputs if any, otherwise state None>
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
#>
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
# Définir l'action d'erreur pour continuer silencieusement
$ErrorActionPreference = "SilentlyContinue"
# Bibliothèques de fonctions requises
#----------------------------------------------------------[Declarations]----------------------------------------------------------
# Version Script
$sScriptVersion = "1.0"
#Log File Info
$sLogPath = "C:\Tmp"
$sLogName = "Install-Service-RDS.log"
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
Start-Transcript -Path $sLogFile -NoClobber
#-----------------------------------------------------------[Functions]------------------------------------------------------------
#--------------------------------------------------------[Debut Du Script]---------------------------------------------------------
Add-WindowsFeature RDS-RD-Server -Restart
Import-Module RemoteDesktop
Get-Command -Module RemoteDesktop
New-RDSessionDeployment -ConnectionBroker SRV-RDS-01.it-connect.local -SessionHost SRV-RDS-01.it-connect.local -WebAccessServer SRV-RDS-01.it-connect.local
Add-RDServer -Server SRV-RDS-01.it-connect.local -Role RDS-LICENSING -ConnectionBroker SRV-RDS-01.it-connect.local
Set-RDLicenseConfiguration -LicenseServer SRV-RDS-01.it-connect.local -Mode PerUser -ConnectionBroker SRV-RDS-01.it-connect.local
Get-RDLicenseConfiguration
New-RDSessionCollection -CollectionName "RdsApps" -CollectionDescription "Collection RDS pour accéder aux apps IT-Connect" -ConnectionBroker SRV-RDS-01.it-connect.local -SessionHost SRV-RDS-01.it-connect.local
Set-RDSessionCollectionConfiguration -CollectionName "RdsApps" -TemporaryFoldersPerSession $false -TemporaryFoldersDeletedOnExit $false
Set-RDSessionCollectionConfiguration -CollectionName "RdsApps" -DisconnectedSessionLimitMin 360 -IdleSessionLimitMin 120
Get-RDSessionCollectionConfiguration -CollectionName "RdsApps" -Connection
New-RDRemoteApp -Alias WordPad -DisplayName WordPad -FilePath "C:\Program Files\Windows NT\Accessories\wordpad.exe" -ShowInWebAccess 1 -CollectionName "RdsApps" -ConnectionBroker SRV-RDS-01.it-connect.local
#---------------------------------------------------------[Fin Du Script]----------------------------------------------------------
Stop-Transcript

View File

@ -0,0 +1,123 @@
<#
.SYNOPSIS
<Overview of script>
.NOTES
Version : 1.0
Author : Hubert CORNET
Creation Date : <Date>
Purpose/Change : <Initial script development>
.LINK
https://www.tips-of-mine.fr
.EXEMPLE
<Example goes here. Repeat this attribute for more than one example>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
<Inputs if any, otherwise state None>
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
#>
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
# Définir l'action d'erreur pour continuer silencieusement
$ErrorActionPreference = "SilentlyContinue"
#Import ServerManger Module (adds Add-WindowsFeature cmdlet)
Import-Module ServerManager
#----------------------------------------------------------[Declarations]----------------------------------------------------------
# Version Script
$sScriptVersion = "1.0"
#Log File Info
$sLogPath = "C:\Tmp"
$sLogName = "Install-Service-SNMP.log"
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
Start-Transcript -Path $sLogFile -NoClobber
$pmanagers = @("10.0.4.57","centreon.tips-of-mine.local") # ADD YOUR MANAGER(s) in format @("manager1","manager2")
$CommString = @("Public","SUP-MON-PRIV") # ADD YOUR COMM STRING(s) in format @("Community1","Community2")
#-----------------------------------------------------------[Functions]------------------------------------------------------------
#--------------------------------------------------------[Debut Du Script]---------------------------------------------------------
# Verifiez si les services SNMP sont deja installes (il doit y en avoir entre 2 et 3 services)
$CheckSNMPServices = Get-WindowsFeature -Name *SNMP*
#Si il y a au moins un service alors nous allons controler l'ensemble des services
If ($checkSNMPServices.Installed -eq "True") {
Write-Output "Les services SNMP ont été trouvés sur ce systéme. Vérification de l'installation des sous-composants."
#Vérifier si le service SNMP est installé (note : "Service SNMP" et non "Services")
$CheckSNMPService = Get-WindowsFeature | Where-Object { $_.Name -eq "SNMP-Service" }
If ($CheckSNMPService.Installed -ne "True") {
#Install/activation SNMP Service
Write-output "Le service SNMP n'est pas actuellement installé : Installation"
Install-WindowsFeature SNMP-Service -IncludeAllSubFeature -IncludeManagementTools | Out-Null
}
Else {
Write-Output "Service SNMP non nécessaire"
}
#Check If SNMP-WMI-Provider is Installed
$CheckWMIProvider = Get-WindowsFeature | Where-Object { $_.Name -eq "SNMP-WMI-Provider" }
If ($CheckWMIProvider.Installed -ne "True") {
#Installation/Activation des services SNMP
Write-output "SNMP WMI Provider n'est pas actuellement installé : Installation"
Install-WindowsFeature SNMP-WMI-Provider -IncludeAllSubFeature -IncludeManagementTools | Out-Null
}
Else {
Write-Output "SNMP WMI Provider non nécessaire"
}
$check = Get-WindowsFeature -Name SNMP-Service
##Verify Windows Services Are Enabled
If($check.Installed -eq "True") {
Write-Host "Configuring SNMP Services..."
#Set SNMP Permitted Manager(s) ** WARNING : This will over write current settings **
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v 1 /t REG_SZ /d localhost /f | Out-Null
#Set SNMP Traps and SNMP Community String(s) - *Read Only*
Foreach ($String in $CommString) {
reg add ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /f | Out-Null
# Set the Default value to be null
reg delete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /ve /f | Out-Null
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v $String /t REG_DWORD /d 4 /f | Out-Null
$i = 2
Foreach ($Manager in $PManagers) {
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v $i /t REG_SZ /d $manager /f | Out-Null
reg add ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /v $i /t REG_SZ /d $manager /f | Out-Null
$i++
}
}
}
}
#Sinon nous installatons l'ensemble des composants
Else {
Write-Output "Aucun service SNMP n'a été trouvé installé sur ce systéme. Installation de SNMP et de ses sous-composants"
#Installation/Activation des services SNMP
Install-WindowsFeature SNMP-Service -IncludeAllSubFeature -IncludeManagementTools | Out-Null
}
#---------------------------------------------------------[Fin Du Script]----------------------------------------------------------
Stop-Transcript

View File

@ -0,0 +1,58 @@
<#
.SYNOPSIS
<Overview of script>
.NOTES
Version : 1.0
Author : Hubert CORNET
Creation Date : 26/11/2022
Purpose/Change : <Initial script development>
.LINK
https://www.tips-of-mine.fr
.EXEMPLE
<Example goes here. Repeat this attribute for more than one example>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
<Inputs if any, otherwise state None>
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
#>
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
# Définir l'action d'erreur pour continuer silencieusement
$ErrorActionPreference = "SilentlyContinue"
# Bibliothèques de fonctions requises
#----------------------------------------------------------[Declarations]----------------------------------------------------------
# Version Script
$sScriptVersion = "1.0"
#Log File Info
$sLogPath = "C:\Tmp"
$sLogName = "Key-Activation.log"
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
Start-Transcript -Path $sLogFile -NoClobber
#-----------------------------------------------------------[Functions]------------------------------------------------------------
#--------------------------------------------------------[Debut Du Script]---------------------------------------------------------
DISM /online /Set-Edition:ServerStandard /ProductKey:VDYBN-27WPP-V4HQT-9VMD4-VMK7H /AcceptEula
#DISM /online /Set-Edition:ServerDatacenter /ProductKey:WX4NM-KYWYW-QJJR4-XV3QB-6VM33 /AcceptEula
#---------------------------------------------------------[Fin Du Script]----------------------------------------------------------
Stop-Transcript

View File

@ -0,0 +1,234 @@
<#
.SYNOPSIS
<Overview of script>
.NOTES
Version : 1.0
Author : Hubert CORNET
Creation Date : <Date>
Purpose/Change : <Initial script development>
.LINK
https://www.tips-of-mine.fr
.EXEMPLE
<Example goes here. Repeat this attribute for more than one example>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
<Inputs if any, otherwise state None>
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
#>
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
# Définir l'action d'erreur pour continuer silencieusement
$ErrorActionPreference = "SilentlyContinue"
Param
(
[Parameter(Mandatory=$false)]
[Alias('Computer')][String[]]$ComputerName=$Env:COMPUTERNAME,
[Parameter(Mandatory=$false)]
[Alias('NTFS')][Switch]$NTFSPermission,
[Parameter(Mandatory=$false)]
[Alias('Cred')][System.Management.Automation.PsCredential]$Credential
)
$Database = @()
$DatabaseNTFS = @()
$RecordErrorAction = $ErrorActionPreference
# Définir l'action d'erreur pour continuer silencieusement
$ErrorActionPreference = "SilentlyContinue"
# Bibliothèques de fonctions requises
#----------------------------------------------------------[Declarations]----------------------------------------------------------
# Version Script
$sScriptVersion = "1.0"
#Log File Info
$sLogPath = "C:\Tmp"
$sLogName = "<script_name>.log"
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
Start-Transcript -Path $sLogFile -NoClobber
#-----------------------------------------------------------[Functions]------------------------------------------------------------
Function GetSharedFolderPermission($ComputerName) {
#test server connectivity
$PingResult = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet
If($PingResult) {
#check the credential whether trigger
If($Credential) {
$SharedFolderSecs = Get-WmiObject -Class Win32_LogicalShareSecuritySetting -ComputerName $ComputerName -Credential $Credential -ErrorAction SilentlyContinue
}
Else {
$SharedFolderSecs = Get-WmiObject -Class Win32_LogicalShareSecuritySetting -ComputerName $ComputerName -ErrorAction SilentlyContinue
}
Foreach ($SharedFolderSec in $SharedFolderSecs) {
$Objs = @() #define the empty array
$SecDescriptor = $SharedFolderSec.GetSecurityDescriptor()
Foreach($DACL in $SecDescriptor.Descriptor.DACL) {
$DACLDomain = $DACL.Trustee.Domain
$DACLName = $DACL.Trustee.Name
If($DACLDomain -ne $null) {
$UserName = "$DACLDomain\$DACLName"
}
Else {
$UserName = "$DACLName"
}
#customize the property
$Properties = @{'ComputerName' = $ComputerName
'ConnectionStatus' = "Success"
'SharedFolderName' = $SharedFolderSec.Name
'SharedFolderPath' = $SharedFolder.Path
'SecurityPrincipal' = $UserName
'FileSystemRights' = [Security.AccessControl.FileSystemRights]$($DACL.AccessMask -as [Security.AccessControl.FileSystemRights])
'AccessControlType' = [Security.AccessControl.AceType]$DACL.AceType}
$SharedACLs = New-Object -TypeName PSObject -Property $Properties
$Objs += $SharedACLs
}
$Objs|Select-Object ComputerName,ConnectionStatus,SharedFolderName,SharedFolderPath,SecurityPrincipal, FileSystemRights,AccessControlType
}
}
Else {
$Properties = @{'ComputerName' = $ComputerName
'ConnectionStatus' = "Fail"
'SharedFolderName' = "Not Available"
'SecurityPrincipal' = "Not Available"
'FileSystemRights' = "Not Available"
'AccessControlType' = "Not Available"}
$SharedACLs = New-Object -TypeName PSObject -Property $Properties
$Objs += $SharedACLs
$Objs|Select-Object ComputerName,ConnectionStatus,SharedFolderName,SharedFolderPath,SecurityPrincipal, FileSystemRights,AccessControlType
}
}
Function GetSharedFolderNTFSPermission($ComputerName) {
#test server connectivity
$PingResult = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet
If($PingResult) {
#check the credential whether trigger
If($Credential) {
$SharedFolders = Get-WmiObject -Class Win32_Share -ComputerName $ComputerName -Credential $Credential -ErrorAction SilentlyContinue
}
Else {
$SharedFolders = Get-WmiObject -Class Win32_Share -ComputerName $ComputerName -ErrorAction SilentlyContinue
}
Foreach($SharedFolder in $SharedFolders) {
$Objs = @()
$SharedFolderPath = [regex]::Escape($SharedFolder.Path)
If($Credential) {
$SharedNTFSSecs = Get-WmiObject -Class Win32_LogicalFileSecuritySetting -Filter "Path='$SharedFolderPath'" -ComputerName $ComputerName -Credential $Credential
}
Else {
$SharedNTFSSecs = Get-WmiObject -Class Win32_LogicalFileSecuritySetting -Filter "Path='$SharedFolderPath'" -ComputerName $ComputerName
}
$SecDescriptor = $SharedNTFSSecs.GetSecurityDescriptor()
Foreach($DACL in $SecDescriptor.Descriptor.DACL) {
$DACLDomain = $DACL.Trustee.Domain
$DACLName = $DACL.Trustee.Name
If($DACLDomain -ne $null) {
$UserName = "$DACLDomain\$DACLName"
}
Else {
$UserName = "$DACLName"
}
#customize the property
$Properties = @{'ComputerName' = $ComputerName
'ConnectionStatus' = "Success"
'SharedFolderName' = $SharedFolder.Name
'SharedFolderPath' = $SharedFolder.Path
'SecurityPrincipal' = $UserName
'FileSystemRights' = [Security.AccessControl.FileSystemRights]$($DACL.AccessMask -as [Security.AccessControl.FileSystemRights])
'AccessControlType' = [Security.AccessControl.AceType]$DACL.AceType
'AccessControlFalgs' = [Security.AccessControl.AceFlags]$DACL.AceFlags }
$SharedNTFSACL = New-Object -TypeName PSObject -Property $Properties
$Objs += $SharedNTFSACL
}
$Objs |Select-Object ComputerName,ConnectionStatus,SharedFolderName,SharedFolderPath,SecurityPrincipal,FileSystemRights, `
AccessControlType,AccessControlFalgs -Unique
}
}
Else {
$Properties = @{'ComputerName' = $ComputerName
'ConnectionStatus' = "Fail"
'SharedFolderName' = "Not Available"
'SecurityPrincipal' = "Not Available"
'FileSystemRights' = "Not Available"
'AccessControlType' = "Not Available"
'AccessControlFalgs' = "Not Available" }
$SharedNTFSACL = New-Object -TypeName PSObject -Property $Properties
$Objs += $SharedNTFSACL
$Objs |Select-Object ComputerName,ConnectionStatus,SharedFolderName,SharedFolderPath,SecurityPrincipal,FileSystemRights, `
AccessControlType,AccessControlFalgs -Unique
}
}
#--------------------------------------------------------[Debut Du Script]---------------------------------------------------------
Clear-Host
$Table = New-Object 'System.Collections.Generic.List[System.Object]'
$ListServeur = Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*'}
Foreach ($Serveur in $ListServeur) {
Try {
Test-Connection -computername $Serveur.DNSHostName -Count 1 -ErrorAction stop | Out-Null
Write-host $Serveur.DNSHostName
$ListePartage = GetSharedFolderPermission -ComputerName $Serveur.DNSHostName
#$ListePartageNFTS = GetSharedFolderNTFSPermission -ComputerName $Serveur.DNSHostName
If (($ListePartage).Count -eq 0) {
}
Else {
$Database += $ListePartage
}
#If (($ListePartageNFTS).Count -eq 0) {
#
#}
#Else {
# $DatabaseNFTS += $ListePartageNFTS
#}
}
Catch [System.Net.NetworkInformation.PingException] {
Write-Warning "$Serveur.DNSHostName ne répond pas"
}
}
$Database | Out-GridView
#$DatabaseNFTS | Out-GridView
#restore the error action
$ErrorActionPreference = $RecordErrorAction
#---------------------------------------------------------[Fin Du Script]----------------------------------------------------------
Stop-Transcriptg

View File

@ -0,0 +1,87 @@
<#
.SYNOPSIS
Lorsque l'on doit modifier un ou plusieur fichier sur des serveurs de facon rapide et relancer le service associé à l'application
.NOTES
Version: 1.0
Author: Hubert CORNET
Creation Date: 15/11/2022
Purpose/Change:
.LINK
https://www.tips-of-mine.fr
.EXEMPLE
.DESCRIPTION
Permet de modifier le contenu d'un fichier et relancer le service assosié
.PARAMETER <Parameter_Name>
.INPUTS
.OUTPUTS
#>
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
# Définir l'action d'erreur pour continuer silencieusement
$ErrorActionPreference = "SilentlyContinue"
# Bibliothèques de fonctions requises
#----------------------------------------------------------[Declarations]----------------------------------------------------------
# Version Script
$sScriptVersion = "1.0"
#Log File Info
$sLogPath = "C:\Tmp"
$sLogName = "<script_name>.log"
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
#-----------------------------------------------------------[Functions]------------------------------------------------------------
#------------------------------------------------------------[Script]--------------------------------------------------------------
cls
# Liste l'ensemble des serveurs d'un domaine
$ListServer = Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*'}
Foreach ($ServerName in $ListServer) {
Try {
Test-Connection -computername $ServerName.DNSHostName -Count 1 -ErrorAction stop | Out-Null
Write-host $ServerName.DNSHostName
$ServerFolder = Invoke-Command -ComputerName $ServerName.DNSHostName -ScriptBlock{
$FileToCheck = "C:\Program Files\CYBERWATCH SAS\CyberwatchAgent\agent.conf"
If (Test-Path $FileToCheck -PathType leaf) {
Write-host " - Fichier present"
# Ouvre le fichier
$content = Get-Content $FileToCheck
# Modifie la ligne 12
$content[11] = "enabled = True"
# Sauvegarde le fichier
$content | Set-Content -Path $FileToCheck
# relance le service
Restart-Service -Name CyberwatchService
}
Else {
Write-host " - pas de fichier"
}
}
}
Catch [System.Net.NetworkInformation.PingException] {
Write-Warning "$ServerName ne répond pas"
}
}

View File

View File

@ -0,0 +1,60 @@
<#
.SYNOPSIS
<Overview of script>
.NOTES
Version : 1.0
Author : Hubert CORNET
Creation Date : 18/11/2022
Purpose/Change : <Initial script development>
.LINK
https://www.tips-of-mine.fr
.EXEMPLE
<Example goes here. Repeat this attribute for more than one example>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
<Inputs if any, otherwise state None>
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
#>
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
Param(
[Parameter(Mandatory=$True,Position=1)]
[int]$ComputerName
)
# Définir l'action d'erreur pour continuer silencieusement
$ErrorActionPreference = "SilentlyContinue"
# Bibliothèques de fonctions requises
#----------------------------------------------------------[Declarations]----------------------------------------------------------
# Version Script
$sScriptVersion = "1.0"
#Log File Info
$sLogPath = "C:\Tmp"
$sLogName = "Reboot-Cumputer-Remote.log"
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName
Start-Transcript -Path $sLogFile -NoClobber
#-----------------------------------------------------------[Functions]------------------------------------------------------------
#--------------------------------------------------------[Debut Du Script]---------------------------------------------------------
Restart-Computer -ComputerName $ComputerName -force
#---------------------------------------------------------[Fin Du Script]----------------------------------------------------------
Stop-Transcript

View File

@ -0,0 +1,4 @@
Invoke-Command -ComputerName 'localhost' -ScriptBlock { logoff 1 }
Invoke-Command -ComputerName 'localhost' -ScriptBlock { logoff 2 }
Invoke-Command -ComputerName 'localhost' -ScriptBlock { logoff 3 }
Invoke-Command -ComputerName 'localhost' -ScriptBlock { logoff 4 }

View File

@ -0,0 +1,22 @@
#
# Change service user name and password
# www.sivarajan.com
#
clear
$UserName = "CONNECT\Tomcat"
$Password = "Password"
$Service = "TomcatCPT16073" #Change service name with your service name
$Cred = Get-Credential #Prompt you for user name and password
Import-CSV C:\Scripts\input.csv | % {
$ServerN = $_.ServerName
$svcD=gwmi win32_service -computername $ServerN -filter "name='$service'" -Credential $cred
$StopStatus = $svcD.StopService()
If ($StopStatus.ReturnValue -eq "0") # validating status - http://msdn.microsoft.com/en-us/library/aa393673(v=vs.85).aspx
{write-host "$ServerN -> Service Stopped Successfully"}
$ChangeStatus = $svcD.change($null,$null,$null,$null,$null,$null,$UserName,$Password,$null,$null,$null)
If ($ChangeStatus.ReturnValue -eq "0")
{write-host "$ServerN -> Sucessfully Changed User Name"}
$StartStatus = $svcD.StartService()
If ($ChangeStatus.ReturnValue -eq "0")
{write-host "$ServerN -> Service Started Successfully"}
}