Hey! Colleagues.
Sorry for my English, I use an automatic translator.
Here is my powershell script (packed in exe)
param
(
[string]$User,
[String[]]$Computers
)
[System.Windows.Forms.MessageBox]::Show("сервера" + $computets)
foreach ($computer in $Computers)
{
[System.Windows.Forms.MessageBox]::Show("сервера" + $computer)
try
{
Invoke-Command -ComputerName $computer -ScriptBlock {
param ($user)
$localpath = 'c:\users\' + $user Get-WmiObject -Class Win32_UserProfile | Where-Object { $_.LocalPath -eq $localpath } | Remove-WmiObject} -ArgumentList $user
[System.Windows.Forms.MessageBox]::Show('Пользователь:' + $User + ' очищен с фермы:' + $computer)
}
catch
{
[System.Windows.Forms.MessageBox]::Show('Пользователь не вышел из сеанса на сервере '+$computer)
}
}
from C # I am passing a value to it in the form:
public static void DeleteUserProfile(string user, string ws)
{
string query = TerminalServer.Where(x => x == ws).FirstOrDefault().ToUpper();
string[] RDS = { "ALDEBARAN", "ALTAIR", "ANTARES", "TANATOS"};
string[] FDRDS = { "PHOEBE", "JULIET"};
string[] JDRDS = { "Erriapo" };
string[] WHRDS = { "Thrym" };
string[] Servers = { "Aldebaran", "Altair", "Antares", "Tanatos" };
if ((query == "ALDEBARAN") || (query == "ALTAIR") || (query == "ANTARES") || (query == "TANATOS"))
{
ProcessStartInfo startInfo = new ProcessStartInfo(@"\\poison\rf\Reg\clearprofiles.exe");
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = $"-user {user} -Computers {Servers}";
Process.Start(startInfo);
}
}
I can't figure out how to pass an array to powershell
:(
I created a breakpoint in the code PS and get the value Servers param = "system.string[]";
[String[]]$Computers
[System.Windows.Forms.MessageBox]::Show("Servers param" + $computers)
