Trying to delete a file with Powershell script ran by a service but issues with uac

I'm having issues with a script that will delete a file on the C-Drive of a server. the script looks like this:
param(
[Parameter(Mandatory=$true)][string]$hostname
$StrFileName = "C:\Program Files\NSClient++\nsclient.log"
$LogLocal="c:\Nagios\naf_delete_nscp_log_file.log"
$Date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
"$date : NSClient logfile deletion requested on $hostname" | Out-File -filepath $LogLocal -Append
If (Test-Path "$strFileName"){
Remove-Item $strFileName -Force
$Date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
"$date : NSClient logfile deleted on $hostname" | Out-File -filepath $LogLocal -Append
The script is initiated from a Nagios quick action which will use nrpe to pass the host as parameter and make the nscp service, which runs as local system, run it. It works perfectly on servers that have no uac enabled, but I can't get it to work on servers
with uac. I've tried numerous options, but none seem to work. Any tips or advice to get this working with Powershell v2 code on servers with uac enabled is highly appreciated.
Thanks.
Willem

Hi Willem,
one thing to note: I don't see why your script itself has a hostname parameter.
One way around UAC has always been the Windows Task Scheduler. If you register a task as System run and triggered by an event, you can simply call the event locally (which doesn't require admin permissions) and it will perform the task.
I don't know how your Nagios construct works and the script by itself doesn't make much sense. If you want advice on how to do this without resorting to tasks, I'd need to know more about the system you are using.
Cheers,
Fred
There's no place like 127.0.0.1

Similar Messages

  • Is it possible to monitor State change of a .CSV file using powershell scripting ?

    Hi All,
    I just would like to know Is it possible to monitor State change of a .CSV file using powershell scripting ? We have SCOM tool which has that capability but there are some drawbacks in that for which we are not able to utilise that. So i would like
    to know is this possible using powershell.
    So if there is any number above 303 in the .CSV file then i need a email alert / notification for the same.
    Gautam.75801

    Hi Jrv,
    Thank you very much. I modified the above and it worked.
    Import-Csv C:\SCOM_Tasks\GCC2010Capacitymanagement\CapacityMgntData.csv | ?{$_.Mailboxes -gt 303} | Export-csv -path C:\SCOM_Tasks\Mbx_Above303.csv;
    Send-MailMessage -Attachments "C:\SCOM_Tasks\Mbx_Above303.csv" -To “[email protected]" -From “abc@xyz" -SMTPServer [email protected] -Subject “Mailboxex are above 303 in Exchange databases” -Body “Mailboxex are above 303 in Exchange databases" 
    Mailboxex - is the line which i want to monitor if the values there are above 303. And it will extract the lines with all above 303 to another CSV file and 2nd is a mail script to email me the same with the attachment of the 2nd extract.
    Gautam.75801

  • I've can't open any applications on my Mac ! I tried to delete some files from safari (history) and then none of the apps including iphoto, safari, mail, facetime. I don't know how to fix it, help ? any idea ?

    I've can't open any applications on my Mac ! I tried to delete some files from safari (history) and then none of the apps including iphoto, safari, mail, facetime. I don't know how to fix it, help ? any idea ?

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It’s unlikely to solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of the test is to determine whether the problem is caused by third-party software that loads automatically at startup or login, or by a peripheral device. 
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode and log in to the account with the problem. Note: If FileVault is enabled, or if a firmware password is set, or if the boot volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including sound output andWi-Fi on certain iMacs. The next normal boot may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin. Test while in safe mode. Same problem? After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of the test.

  • Problem when trying to delete rejected files in LR 5.2.

    When I try to delete rejected files I enter the library module, select all photographs by their rejected flag status and using the cmd and backspace keys, I get the usual message offering me the options of canceling, deleting from the disk or remove from catalogue.  Choosing delete from disc I then get a pop up window that says there were (x amount) of files that could not be moved to the trash folder.  It does this whether I try to delete all images flagged as rejected at the same time or go file by file and delete them in ones and twos.  I am using a mac.  The trash folder is empty.

    Got it sorted so I thought I would share the solution here:  The problem wasnt related to LR 5.2 but was to do with Mac OS X 10.8.5 AKA Mountain Lion.  I had also noticed that I was having an issue around deleting anything on my MAC.  When I tried to delete a file from anywhere I was asked to submit my password.  The message I got was finder wants to make a change please submit password.  I checked through the mountain Lion forums and found a solution here; https://discussions.apple.com/message/20499360#20499360%2320499360
    I implemented it and the problem has dissappeared.

  • Trying to delete some files from a flash template (.fla file) in flash

    Hi I am trying to delete some files from a flash template I purchased,  when I open the .fla file in flash and go into the library, I would like  to delete the contact box and the mp3 player, when I locate those files  in the library and delete the files, the website no longer opens up (it  will not work when I delete those files from the library) what am I  doing wrong ? please help, I am fairly new to flash.

    Ned - Nice to have guys like your good self giving the advice you do!
    Hope the chap sorts out his mp3 library Problems!
    For my part, I don't want to even try come to terms with FLASH - great as it is.
    If you would like to have the job of making changes for me @  Footballtipping.co.uk/ - let me know. Contact - [email protected]
    You will be rewarded to your liking! -
    Regards all & keep at it!
    Mike Roche

  • ITunes Match has stopped uploading - every file errors and says waiting - I have tried to delete the files and use other formats etc.  I have had the service since Day 1 and NEVER had an issue.  It didn't start until the Delete from Cloud switch to Hide

    iTunes Match has stopped uploading - every file errors and says waiting - I have tried to delete the files and use other formats etc.  I have had the service since Day 1 and NEVER had an issue.  It didn't start until the Delete from Cloud switch to Hide from cloud - the files that do not upload show grayed out on my other devices.

    Have you confirmed that you successfull purged iTunes Match by also looking on an iOS device?  If so, keep in mind that Apple's servers may be experiencing a heavy load right now.  They just added about 19 countries to the service and I've read a few accounts this morning that suggests all's not running perfectly right now.

  • Update a filed value with powershell script with ordery by and where condition

    Hi
    I have below powershell script to update list columns but  how i update a field value with ordery by a column and where condition
    below is the part of my script
    $list = $web.Lists[$listName]
    $items = $list.items
    $internal_counter = 1
    #Go through all items
    foreach($item in $items)
    if($item["CourtNO"] -eq $null)
    #if($item["CourtNo"] -eq '1')
    $item["CaseNo"] = $internal_counter
    #how to add a column ordery by Title
    # and where Title field value from 1 to 10
    $internal_counter++
    adil

    Hi,
    You mean that you only need to update all items with Title field value in range 1..10 and order by them before run the loop statement update?
    If so, use CAML query to get the items only match the condition.
    #Build Query
    $spQuery = New-Object Microsoft.SharePoint.SPQuery
    $query = '<Where><And><Gte><FieldRef Name="Title" /><Value Type="Text">0</Value></Gte><Lte><FieldRef Name="Title" /><Value Type="Text">10</Value></Lte></And></Where><OrderBy><FieldRef
    Name="Title"/></OrderBy>'
    $spQuery.Query = $query
    $spQuery.RowLimit = $list.ItemCount
    $items = $list.GetItems($spQuery)
    Hope this help!
    /Hai
    Visit my blog: My Blog | Visit my forum:
    SharePoint Community for Vietnamese |
    Bamboo Solution Corporation

  • I have MacBook,the disk is already full.when I open it I can't see the icons below.im trying to delete my files but I can't...

    I have MacBook,the disk is already full.when I open it I can't see the icons below.im trying to delete my files but I can't...what should I do?my screen shows only color blue screen and apple icon,file,edit,view,share,window and help on the upper left of the screen...

    If she can't remember the ID/password, she will need to go to https://iforgot.apple.com to recover it/reset the password or she will have to call Apple and speak to someone in account security.

  • HT2237 I am trying to delete unwanted files from an external drive and am getting error code -50.  What do I need to do to clear this and delete the files?

    Can someone tell me how to clear this error.  I am trying to delete unwanted files from an external drive and get error code -50.  How do I clear this so I can delete these files?  Thanks.

    Re: Error Code-50 when trying to copy or delete files on external hard drive

  • Because me and my parents have the same apple id, my new phone synced all of their songs on to my iPhone. I tried to delete them or transfer them off my phone to iTunes but it wouldn't work. What do I do?

    Because me and my parents have the same apple id, my new phone synced all of their songs on to my iPhone. I tried to delete them or transfer them off my phone to iTunes but it wouldn't work. What do I do?

    im so happy I have a iTunes Card Code absolutely free! I got it at http://linkbitty.com/freeitunes2014

  • TS4268 Help! Probably you have never experienced this, but I have lost the ability to iMessage.  When I try to turn on iMessage, it tells me that "an error occurred while trying to turn on iMessage."   It's not a huge deal, but people with iPhones can't t

    Help!
    Probably you have never experienced this, but I have lost the ability to iMessage.
    When I try to turn on iMessage, it tells me that "an error occurred while trying to turn on iMessage." 
    It's not a huge deal, but people with iPhones can't text me back unless they try to re-send after finding out that their message wasn't delivered.
    Help!
    I think I have gone through every support option available, short of
    Scheduling an appointment at the Genius Bar. But I have been to the store three times in the last three weeks.
    To solve a different problem, the folks at the store replaced my iPhone 4S.
    I came home and loaded my backup onto the new phone. Everything EXCEPT iMessage seems to be working great.
    I would really appreciate any feedback...

    Help!
    Probably you have never experienced this, but I have lost the ability to iMessage.
    When I try to turn on iMessage, it tells me that "an error occurred while trying to turn on iMessage." 
    It's not a huge deal, but people with iPhones can't text me back unless they try to re-send after finding out that their message wasn't delivered.
    Help!
    I think I have gone through every support option available, short of
    Scheduling an appointment at the Genius Bar. But I have been to the store three times in the last three weeks.
    To solve a different problem, the folks at the store replaced my iPhone 4S.
    I came home and loaded my backup onto the new phone. Everything EXCEPT iMessage seems to be working great.
    I would really appreciate any feedback...

  • I am trying to delete a page from a pdf using Acrobat X Pro but the delete option is greyed out. Why

    I am trying to delete a page from a pdf using Acrobat X Pro but the delete option is greyed out.  Does anyone know why?

    Post your question in the forum for Adobe Acrobat.

  • TS2512 i m trying to convert dpx files to mov in colour 1.5.3 but in file browser files are not seen in proper order for ex files names are 12345 it is coming as 23145 bcoz of which in output also its coming in wrong order

    i m trying to convert dpx files to mov in colour 1.5.3 but in file browser files are not seen in proper order for ex files names are 12345 it is coming as 23145 bcoz of which in output also its coming in wrong order

    1) What you downloaded should be a packed file (zip, tar.gz, etc) that needs to be unpacked into the directory of your choice.
    2) & 3) are answered by Ant's installation documentation (the page you're quoting from):
    http://ant.apache.org/manual/index.html

  • MPS 200 with J 4.6. We are having issues with encryption and unable to install latest, J 4.7.2

    We have an MPS 200 with J 4.6. We are having issues with encryption and the tech assigned to our TAC case informed us that version J 4.7.2 would resolve the issue per release notes (confirmed). Unfortunately we have been unable to install latest, J 4.7.2. Every time we select the 4000j472.tar.gz file, the MPS displays software upgrade failed. We have used IE 8, 9 and 11 and have opened them up as much as possible, still no joy. We have unzipped the file, but do not know which file to select for the install.
    Would appreciate any assist.

    As the others have suggested - download the file again - and check that the MD5 Checksum (with something like WinMD5) of what you have downloaded matches what it should be (for J4.7.2 is b328946e6ca24f181c937d90d8e5cc12).  Then upload the .tar.gz file as downloaded (wihtout extracting it).
    Wayne
    Please remember to rate responses and to mark your question as answered if appropriate.

  • I have an ipod and an iphone 3GS and a wireless LAN device, with my ipod I have a connection, but not with my iphone ... why is that?

    I have an ipod and an iphone 3GS and a wireless LAN device, with my ipod I have a connection, but not with my iphone ... why is that?

    - An iPod can only sync with one iTunes library. Yu can however manage music and videos among different computers by:
    Using iPhone, iPad, or iPod with multiple computers
    - To change syncing computer, move all the media to compute r#2
    - Connect the iPod to #2 and make a backup by right clicking on the iPod under Devices in iTunes and select Back Up
    - Restore the iPod from that backup
    Note tha the iPod backup the iTunes makes does not include synced media like apps and music.

Maybe you are looking for

  • PS CC issue on a Surface Pro 2

    Howdy! So, everything is working great in PS CC on my Surface Pro 2, except if i rotate my tablet to portrait mode.. The main window stops with a bunch of empty space below it. It will not stretch any further down than what you see. Also, looks like

  • Missing component to access (read) a PDF file Adobe reader 8

    When I try to open a PDF file it says there are some missing components to complete the operation and it sends me to the Adobe Web page (Adobe Acrobat plug in Finder) I already asked to the author of the file and followed his installation instruction

  • Nomad Jukebox Zen Xtra PLEASE HE

    My player was locked on the EAX screen, and I figured out how to get to the rescue mode, and I clicked "Clean Up" and then pressed the check, and then it went back to the rescue mode screen and nothing's happening. Where do I go from here? What does

  • Snippet to Upload a document

    I am looking for a portlet/snippet that allows me to programatically upload a document into the knowledge directory. I do not want to create just a link, rather I need to upload the content to the DR and also create a card. Phil Orion | [email protec

  • How can I reduce a 5MB photo to 4.5MB without cropping?

    For a photo contest I can't submit photos over 5MB, yet the 3 photos I have in the JPEG format in iPhoto to submit are 5.1MB to 8MB in size. Cropping is not an option. Any ideas??? Thanx