Get-Process cannot get the latest path - powershell

considering the following scenario:
I run the executable on the server
I renamed the executable files to a different one while the process is still running.
then use get-process -ID 50620 | Select * to list detail information of this specific process
the path shows previous data, while the actual executable file name was changed already...
how can I get the latest file name from the PowerShell?
Thanks!
why i am asking this:
we are using Terminal server for PDA applications, so once we updated the executable on server, we modify the pervious executable name to different one so when RDP users login system will automatically load the new executable.
just trying to get those sessions running pervious executable(who doesn`t logout and login again since the update) to send message so they know the executable was updated and they have so logout and login soon to load the latest code.

Related

SCCM PowerShell Get Configuration Baseline computers

I am working with Configuration Baselines. I would like to start from "Get-CMBaseline -Name MyBaselineName" and work my way to the name of the machines. I am try to figure out how to get the machines names that are "Compliant", "Error", and "Non-Compliant". I see the names of the machines in "Deployment Status" but I need them via PowerShell.
There are many things that are possible via the built in cmdlets but some just are not (yet?). However it is almost always possible to get the same behavior the console has with wmi (because the console uses wmi itself)
To find out how it is good to know that there is a log file "SMSProv.log" that tells you what the console does for every dialog you open. It is located on the site server wherever you installed the ConfigMgr in a sub-folder Logs (so default would be %Program Files%\Microsoft Configuration Manager\Logs).
So if you use that when checking the deployment status of a baseline you will notice that it basically translates to 3 commands (All in the namespace
Root\SMS\site_<SiteCode>
on your siteserver):
SELECT * FROM SMS_DCMDeploymentCompliantAssetDetails WHERE AssignmentID=<AssignmentID>
SELECT * FROM SMS_DCMDeploymentNonCompliantAssetDetails WHERE AssignmentID=<AssignmentID>
SELECT * FROM SMS_DCMDeploymentErrorAssetDetails WHERE AssignmentID=<AssignmentID>
where AssignemtID is the ID you would get e.g. from
(Get-CMBaselineDeployment -Name "<Your Baslines Name>").AssignmentID
A little exception would be that the console filters the error further by error type but to me it seems like this is maybe not even what you want and you could easily do it in Powershell later if you need to.
The SQL command is also available in most cases in the SMSProv.log, and in some cases it leads to a faster execution. However in this one probably not really and it is a lot more complex most of the time.

get user machines current working directory from perl cgi

i am trying to get the current working directory path using Perl
when i execute from ubuntu: $root#ubuntu:/var/test/geek# firefox http:/localhost/test.html, i get /var/cgi-bin as output in perl cgi page instead of /var/test/geek.
used perl code:
my $pwd=cwd();
bla bla
print "<h1> pwd </h1>";
above code gives path of test.pl not users working directory path
Edit: When i run the script alone from the terminal it works fine. for example:
$root#ubuntu:/var/test/geek# /var/cgi-bin/test.pl
i get /var/test/geek. but when i call the script in html page using submit button it gives path of perl script.
Each process has its own working directory that it inherits from its parent when it gets created.
cwd() returns the current process's working directory.
For a CGI script, the browser doesn't pass its working directory to the server as part of the request. To obtain that, you need to have code running on the client system that submits it. That might be an application that the user download, or possibly, but unlikely, some in-browser code, like Javascript / a Java applet (This info is likely hidden from in-browser code for security reasons though).
(The rest assumes Linux, it will likely differ on other operating systems)
The part below assumes that you are looking for the working directory of a user on the server:
In order to get a specific shell for a specific user's working directory, you would need to identify the PID for the shell and get the working directory from the /proc/<pid>/cwd symlink (To read these, the process must belong to the user running the code, or the code must run as root (Which is a bad idea for a CGI script)...). To get the PID of the shell, you likely need to start from the w command output, or its data source, /var/run/utmp. Sys::Utmp might be useful for this... You might then also need to retreive a whole lot of extra info to find all the processes that might have the working directory that you are looking for.
I think you are mixing the web server and the local user. The web server has a working directory when you run the script, and that is the one that cwd() returns.

How do I use the MOSS script?

I am trying to run MOSS on my Mac OS X and I don't know what mistake I am making. I am not sure whether I am running the command properly or not. I downloaded this file as 'moss', gave this execution permissions and tried to run following:
./moss -l python -c "Assignment 1" -d assignment1/
I got the response as
Checking files . . .
OK
Which is wrong. The assignment1 directory has 4 python scripts. Two files are exactly similar, in one I have rearranged the code and in another I have changed the variable names.
I have sent the email for registration and I have not received any reply. So I am running the code with default user ID.
I also tried running it with sending each of those python files instead of working on a directory, still I get same response.
./moss -l python -c "Assignment 1" 1.py 2.py 3.py 4.py
Steps to get going with MOSS on your Mac:
Send an email at moss#moss.stanford.edu with the mail body containing the email you want to register.
Eg:
registeruser
mail "username#domain" <-- your email
You will then get a reply containing the script that you will need to save as “moss.pl”. Just make sure that your Mac has the “perl” folder within the “/usr/bin/“ folder. Else, change the path of the perl folder on the very first line of the script to be compatible to your machine.
Now set the execute permission using the command “chmod ug+x moss.pl”. This should allow you to send your queries to the Stanford server. If you were to not execute this command then you may be denied the permission to submit any queries.
Now submit the query to the server using the command similar to the following (note the command is not restricted to a single flag (i.e. -l)….refer the comments in the script for USAGE instructions):
“./moss.pl -l python file_1.py file_2.py”
The result on submitting a query such as above would be:
Checking files . . .
OK
Uploading file_1.py ...done.
Uploading file_2.py ...done.
Query submitted. Waiting for the server's response.
http://moss.stanford.edu/results/282371307.
Just review if you have followed all the steps above. I, then, don't see you having any issues getting the results. Maybe you were facing issues bcoz you were not registered initially.
Seems one should be registered to use it, instructions weren't clear on the site. I received the email finally with userid and ran the script, this time it worked.
I think you should resend the email in the format:
registeruser
mail youremail
In the reply email you will get your ID, replace it in the script and run the moss file again. You should get the link for the result.

How to get Write Access to a file/directory locked by another process - Powershell

I've a powershell script which performs some operations on pdf files, email as attachments, then moves the files to an archive.
Script worked properly for about 2 years, however recently I (and also the clients) started getting this error:
The process cannot access the file 'file_name' because it is being used by another process.
From following question I've determined how to check if a file/folder is locked,
How to check if file is being used by another process - Powershell
My Question:
How can I get write access to some file or directory locked by another process?
Thanks for your response.

Refresh $env:path in Powershell?

I have a PowerShell script that checks that a certain directory is on the PATH (by looking through $env:path). It appears that $env:path is loaded and locally scoped by each application on startup, and that scope is passed on to any child applications. So... if someone opens Firefox, downloads my program, runs it, gets a message that they should change their path, fixes the problem, then runs the program again from the Firefox downloads window, they'll get the same message, unless they start my program from Explorer or restart Firefox.
Is there a way to reload $env:path in my PowerShell script so it'll get the current value, as if it were opened from Explorer?
If you were running outside the context of a browser I would tell you to use
[System.Environment]::SetEnvironmentVariable(string name, string value, EnvironmentVariableTarget target)
to change the Path variable for the user. That third parameter allows you to specify Process, User or Machine. If you specify either User or Machine the change is permanent and will appear in the env blocks of all programs that start after that. However, since you are running within the browser I don't think you would be able to do that.
If the user changes their path, that change will be available to future instances of the browser. Another option is to test (Get-Command) for the app you need in the path and if you can't find it, modify $env:Path yourself in the script each time it runs. That is, unless you don't know what the path should be.