Jump to content


Recommended Posts

Would like to execute powershell and batch scripts as admin. Is this possible?

For example, I would like to run sfc.

Is my only option scheduling tasks?

Share this post

Link to post
Share on other sites

I have been unable to get the vast majority of my powershell scripts to run. Scripts that run with no issues when run locally. Many that do not require admin access.

I have tried running them without power shell user impersonation enabled.

I have attempted creating and using an ID that is part of the administrator group.

Enabling the administrator ID than using it as ps user impersonation.

I've verified user impersonation settings in registry are correct.

No errors are being registered in pulseway.

I am testing on a system that does not have a domain. So I have left that field blank. Just in case I attempted to fill it with the system name a few times.

My ultimate goal would be to use the administrator to run commands. I am willing to accept running as a user that is part of the admin group.

An example of a script I am certain works, but now through pulseway.

## Enable Storage Sense
## Ensure the StorageSense key exists
$key = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense"
If (!(Test-Path "$key")) {
    New-Item -Path "$key" | Out-Null
If (!(Test-Path "$key\Parameters")) {
    New-Item -Path "$key\Parameters" | Out-Null
If (!(Test-Path "$key\Parameters\StoragePolicy")) {
    New-Item -Path "$key\Parameters\StoragePolicy" | Out-Null

## Set Storage Sense settings
## Enable Storage Sense
Set-ItemProperty -Path "$key\Parameters\StoragePolicy" -Name "01" -Type DWord -Value 1

## Set 'Run Storage Sense' to Every Week
Set-ItemProperty -Path "$key\Parameters\StoragePolicy" -Name "2048" -Type DWord -Value 7

## Enable 'Delete temporary files that my apps aren't using'
Set-ItemProperty -Path "$key\Parameters\StoragePolicy" -Name "04" -Type DWord -Value 1

## Set 'Delete files in my recycle bin if they have been there for over' to 14 days
Set-ItemProperty -Path "$key\Parameters\StoragePolicy" -Name "08" -Type DWord -Value 1
Set-ItemProperty -Path "$key\Parameters\StoragePolicy" -Name "256" -Type DWord -Value 30

## Set 'Delete files in my Downloads folder if they have been there for over' to 60 days
#Set-ItemProperty -Path "$key\Parameters\StoragePolicy" -Name "32" -Type DWord -Value 1
#Set-ItemProperty -Path "$key\Parameters\StoragePolicy" -Name "512" -Type DWord -Value 60

## Set value that Storage Sense has already notified the user
Set-ItemProperty -Path "$key\Parameters\StoragePolicy" -Name "StoragePoliciesNotified" -Type DWord -Value 1


Share this post

Link to post
Share on other sites

Hi @David-,

From your script I can see that you are trying to set the HKCU registry keys which are for the currently user account, therefore in order to set these keys for the required user account the powershell impersonation is required. If it is not configured, the the HKCU keys will be set for the System account and it will not affect the required user session.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...