I am trying to make a policy that runs on login for one particular user and shows a "Warning" message to that user. Login policies should run in the context of logged in users, so I created a PS script that checks who is logged in with this:
# Get the currently logged-in user
$currentUserName = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
# Check if the username is "user"
if ($currentUserName -eq "user") {
Write-Host "Logged in user is 'user'."
exit 0
} else {
Write-Host "Logged in user is not 'user'. Logged in user is '$currentUserName'."
exit 1
}
and used it as a Condition script for policy and/or module. But the condition always fails with MarkNotApplicable.
I could make an Impersonation account for this one, but
Second problem is that when I tried to use "Send Message" to that PC, it output an error:
ERROR [45] ApiRequest - Error Retrieving API Response: System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:9000
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at RestSharp.Http.<ExecuteRequest>g__GetRawResponse|185_1(WebRequest request)
at RestSharp.Http.ExecuteRequest(String httpMethod, Action`1 prepareRequest)