Bonjour à tous,
je développe une application Windows(c#) pour Windows Server 2016. J'ai stockée un fichier texte qui contient des script powershell (embedded) à mon application. J ' arrive à copier ce script dans un fichier .ps1 mais je remarque qu'il est modifier à certains endroit (caractères qui remplace d'autres). J'ai l'impression que c'est un problème d'encodage mais je n'arrive pas à savoir lequel.
Voici la partie du code qui copie le fichier texte :

string curdir = Directory.GetCurrentDirectory();
String selected = listBox1.SelectedItem.ToString();
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Server_Commander.Resources." + selected +".txt";
Stream stream = assembly.GetManifestResourceStream(resourceName);
StreamReader reader = new StreamReader(stream);
string s = reader.ReadToEnd();
StreamWriter writer = new StreamWriter(selected + ".ps1");
writer.Write(s);
writer.Close();
stream.Close();

Voici le fichier de départ (embedded)

#Disabled firewall
#-----------------
Write-Host -ForegroundColor Magenta "Désactivation du Firewall..."
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
Write-Host -ForegroundColor green "Firewall désactivé!"
#disable IE enhanced security configuration
#------------------------------------------
Write-Host -ForegroundColor Magenta "Désactivation de IE Enhanced Configuration Security..."
$AdminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
$UserKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
Set-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0
Set-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0
Write-Host -ForegroundColor green "IE enhanced Configuration Security désactivé!"
#Set ip address
#--------------
Write-Host -ForegroundColor Magenta "Enter Computer's IP :"
$ip=Read-Host
New-NetIPAddress –IPAddress $ip -DefaultGateway 192.168.1.254 -PrefixLength 24 -InterfaceIndex (Get-NetAdapter).InterfaceIndex
Set-DNSClientServerAddress –InterfaceIndex (Get-NetAdapter).InterfaceIndex –ServerAddresses 192.168.1.1
#Set name of the computer
#------------------------
Write-Host -ForegroundColor Magenta "Enter Computer's name :"
$name=Read-Host
Rename-Computer -NewName $name -Restart


Et voici le fichier à sa sortie :

#Disabled firewall
#-----------------
Write-Host -ForegroundColor Magenta "Désactivation du Firewall..."
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
Write-Host -ForegroundColor green "Firewall désactivé!"
#disable IE enhanced security configuration
#------------------------------------------
Write-Host -ForegroundColor Magenta "Désactivation de IE Enhanced Configuration Security..."
$AdminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
$UserKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
Set-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0
Set-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0
Write-Host -ForegroundColor green "IE enhanced Configuration Security désactivé!"
#Set ip address
#--------------
Write-Host -ForegroundColor Magenta "Enter Computer's IP :"
$ip=Read-Host
New-NetIPAddress –IPAddress $ip -DefaultGateway 192.168.1.254 -PrefixLength 24 -InterfaceIndex (Get-NetAdapter).InterfaceIndex
Set-DNSClientServerAddress –InterfaceIndex (Get-NetAdapter).InterfaceIndex –ServerAddresses 192.168.1.1
#Set name of the computer
#------------------------
Write-Host -ForegroundColor Magenta "Enter Computer's name :"
$name=Read-Host
Rename-Computer -NewName $name -Restart

On peut remarquer que certain caractère ont changés.
Si quelqu'un a une idée.Je vous remercie pour votre attention.