PowerShell Script Issues

ccsshelpdesk
New Contributor III

Hi we are running Bullwall Ransomcare which is working fine on our PC fleet but need to create a Logon Script for our macs.
We ahve tried to install PowerShell on the Macs but we are still running into issues.
And we think its due to some of the details within the PowerShell script relating to windows only. Ideally i would like to convert the PowerShell script to bash but have limited bash knowledge.
Worst case do any places provide paid for services to create bash scripts from PowerShell? or re write it for us?
Cheers for any help anyone can provide.
the ps1 script is below:

# RC Login Script For 1 .. 10 RC server

# Use Comma if u have more that 1 StandBy RC serve Like this : 'https://192.168.1.1','http://rc5.company.local' # #/KDJ 04/06/2020 #/KDJ 22/12/2020 - Add Timeout

$remotehost = 'http://10.20.20.33' $port = 5679

$logout = $False

# Getting Data

$RC_PcName = 'PCNAME=' $env:ComputerName $RC_Domain = 'DOMAIN=' $env:USERDOMAIN $RC_LOGINUSER = 'USER=' $env:UserName $RC_UserName = 'USERNAME=' $env:USERDOMAIN '' $env:UserName $AdObj = New-Object System.Security.Principal.NTAccount($env:UserName) $RC_SID = 'SID=' $AdObj.Translate([System.Security.Principal.SecurityIdentifier]).Value $RC_BaseIPconf = $(ipconfig | where {$ -match 'IPv4.s(d{1,3}.d{1,3}.d{1,3}.d{1,3})' } | out-null; $Matches[1]) $RC_UserIP = 'USERIP=' $RC_BaseIPconf $RC_ClientType = 'CLIENTTYPE=' $RC_GetDate = Get-Date $RC_LoginDate = 'LOGINDATE=' "{0:D2}" -f $RC_GetDate.Year '/' "{0:D2}" -f $RC_GetDate.Month '/' "{0:D2}" -f $RC_GetDate.Day $RC_LoginTime = 'LOGINTIME=' "{0:D2}" -f $RC_GetDate.Hour ':' "{0:D2}" -f $RC_GetDate.Minute ':' "{0:D2}" -f $RC_GetDate.Second $RC_PCSystemType = Get-WMIObject -class Win32_ComputerSystem | Select-Object -ExpandProperty PCSystemType $RC_Mac = 'MACADDR=' $(Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'True'"| Where-Object {$.IPAddress -match $RC_BaseIPconf} | Select -ExpandProperty macaddress) $RC_SessionID = (Get-Process -PID $pid).SessionID $RC_Session = (Get-ItemProperty -Path "HKCU:Volatile Environment$RC_SessionID" -Name "SESSIONNAME" -ErrorAction SilentlyContinue).sessionname $RC_SessionID = 'SESSIONID='+(Get-Process -PID $pid).SessionID

# Query PC System type to execute correct script in Ransomcare

$RC_ClientV = Get-WMIObject -class Win32_OperatingSystem | Select-Object -ExpandProperty ProductType $RC_ClientH = Get-WMIObject -class Win32_ComputerSystem | Select-Object -ExpandProperty PCSystemType switch -Wildcard ($RC_Session) {'RDP' {$RC_Session ='2'} 'ICA' {$RC_Session ='3'} default {$RC_Session ='1'}} if ($RC_ClientV -eq 1) {if ($RC_ClientH -eq 1) { $RC_ClientType ='Desktop'} elseif ($RC_ClientH -eq 2) { $RC_ClientType ='Mobile'} else { $RC_ClientType ='Desktop'} } else { if ($RC_Session -eq 2) {$RC_ClientType ='Terminal'} if ($RC_Session -eq 3) {$RC_ClientType ='Citrix'} if ($RC_Session -eq 1) {$RC_ClientType ='Server'}} $RC_ClientType ='CLIENTTYPE=' + $RC_ClientType $RC_Action='ACTION=Login' ; if($logout -eq $true){$RC_Action='ACTION=logout'}

# Ignore/Accept RC SelfSign

Add-Type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; }
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$allProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $allProtocols

# Build string to sent

$RC_SentData = $RC_PcName ';' $RC_Domain ';' $RC_UserName ';' $RC_SessionID ';' $RC_UserIP+';' $RC_ClientType ';' $RC_LoginDate ';' $RC_LoginTime ';' $RC_Action ';' $RC_SID ';' $RC_Mac ';' + $RC_LOGINUSER

Foreach ($xLoop in $remotehost) { $RC_Api = $xLoop ':' $port $Result=Invoke-WebRequest -Uri $RC_Api/Ransomcare/Admin/api/assets/process-input?input=$RC_SentData -UseBasicParsing -TimeoutSec 20 -ErrorAction Ignore }

0 REPLIES 0