Powershell - RPC, OBJ Null and -Replace ERRORS in MySQL insert query -


I have this inserted query that is not properly included and is really annoying. I briefly explain what I do And what I really want to achieve.

What does my PS script do:

  1. Ping each computer from the database table
  2. If the ping is successful, then get the user name from the computer
  3. Enter the following values ​​in the database table: Username, Hostname, Online (true / false)

Now

Issue 1: If I use the following command:

$ username = Get-WMIObject -ComputerName $ Workstation class Win32_ComputerSystem | Selection-object-expanded property username;

This will include the username names as soon as: SUPER / user1 which is fine but I'm getting rid of "super /" and just by inserting the real user name "user1" first.

I tried to use one of the following but it does not work:

  $ username = Get-WMIObject -ComputerName $ workstation -Class Win32_ComputerSystem | Choose-Object-ExpandParty-Ripley '^. * \\ 'Username; The command will give me two errors in  

Problem 1 :

Can not take action on logic because the argument value is "obj " is null. Change the value of the argument "obj" to a non-empty value.

and

Get-WMIObject: The RPC server is unavailable.

How can I ignore those two errors?

I hope someone can help me because it really is upset. Thanks everyone in advance.

PowerShell Script:

  foreach ($ workstation_list $ pcname) {$ command = $ connection.CreateCommand (); $ Order Connection = $ connection; $ Command.CommandText = "Include workstation_assored (username, hostname, online) values ​​(@ username, @ hostname, @ position)"; ### =============================================== Values ​​assigned as ============== ### parameters ### ===================== == ======================================= $ workstation = $ PCNA; $ Test_ping = Test-Connection -CaptainName $ Workstation -Count 1- Error Action SilentCentinue; $ Position = [boole] (test-connection $ workstation - sq-count 1-index silentlycontent); #if get TRUE username ($ test_ping) {$ username = Get-WMIObject -ComputerName $ workstation -Class Win32_ComputerSystem | Selection-object-expanded property username; Do not make $ Username; #echo -replace '^. * \\ '$ username; #if ping succeeds, but no user is logged ($ username-eq "") {$ username = "no user logged"; }} #end if #if ping is not there, then the name of Username is correct and FalseEf (! $ Test_ping) for the status {$ username = [DBNull] :: Value; } ### ============================================== ===============# Assign parameters with the appropriate criteria ### ======================= ====================================== $ order Parameter.ed ("@username", $ username). Out-null $ command Parameter. Add ("@ Hostname", $ Workstation). Out-null $ command Parameter. Add ("@ position", $ position). Out-null ### ============================================ =================### Execute the command query ### ======================= Try ====================================== {$ command.ExecuteNonQuery () Out of naught; Write - host "successfully entered database"; } Hold {write-host "caught exception"; Type - host "$ _"; } ### ============================================== ===============### Clear parameter value ### ================================== ================================================== Workstation = ""; $ Username = ""; $ Position = ""; $ Test_ping = ""; } With regard to the problem, try this: #end  

for each loop < / P> $ username = (Get-WMIObject -ComputerName $ workstation -Class Win32_ComputerSystem) .UserName $ username = $ username.split ("\") $ username = $ user name [1]

Problem 2 is due to a problem on the remote machine. For some debugin help see the Microsoft Documents.

Although this article corresponds to MS server, most of its customers should also apply to the client machine.


Comments