Can run simple Script with PowerShell, but task scheduler doesn't? - powershell

I created a simple PowerShell script to copy items from a remote location to my google drive, the script runs using the option run with PowerShell.
Get-ChildItem "\\myipaddress\Exports" -Recurse -Filter F7104016E30A0465* |
Copy-Item -Destination "G:\My Drive\storage" -Force
However I am trying to automate the script with task scheduler to run it daily and it is not copy the file into the destination folder. the task does not show an error.
in action tab I select start program and add argument: -ExecutionPolicy Bypass -File C:\test\script.ps1, there is not error on the log but it doesn't show incremental (1 file) in the google drive.

Related

Powershell script to push installation via intune

I am trying to create an intunewin file to update dell command update on all computers (via MS endpoint manager).
Dell CU will not install itself, if the older version of the app is present on the pc. Or rather it will install, but it won't run.
Solution - To create a powershell script, that first uninstalls the older versions of dell CU, and only then installs the newest one.
The code:
Remove-Item -Path "C:\Program Files\Dell\CommandUpdate" -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -Path "C:\Program Files (x86)\Dell\CommandUpdate" -Recurse -Force -EA SilentlyContinue -Verbose
./Dell-Command-Update-Windows-Universal-Application_601KT_WIN_4.5.0_A00_01.EXE
This works just fine, when run like this on my computer. Actually I run the cmd script:
powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File .\script.ps1
Where script.ps1 is the first script above.
So I have 3 files in the folder - the ps1 script, the cmd command, and the EXE file itself. From these 3 I create the intunewin file.
When pushed via intune, the app does not install itself. I can see 'downloading' notification, but never receive installation notification, neither successful nor failed one.
Can this be related to intune settings itself? The detection method and install command are most likely correct and were working before, when I was just using the exe file for intunewin creation.
I have to change this, because Dell CU won't install itself if the older version is there - as mentioned in the first sentence.
I assume this might be related to the powershell code. Maybe intune does not understand
./Dell-Command-Update-Windows-Universal-Application_601KT_WIN_4.5.0_A00_01.EXE
anymore, when it is given intunewin file instead?
If that's the case, how can I modify my script to 'make sense in intune'?
Thank you in advance for all the advices

Powershell script runs but task scheduler wont run it

I have a powershell script that runs in ISE but wont run in Task Scheduler. It is a simple powershell script to move a file... I have it set to run at a specific time in task scheduler, but it wont run. When I try to run it manually from task scheduler, it gets stuck on running. Its moving the file to a mapped drive. I have the task scheduler set to run whether the user is logged on or not and with higest priviledges and its also under an admin account... Based upon research, I found articles about the PSDrive cmdlet if you are using mapped drives but I dont know how to incorporate it into my script...Can anyone help me incorporate the PSDrive cmdlet if this is the issue, thanks.
Set-ExecutionPolicy Bypass -scope Process -Force
$_SourcePath = "C:\lilsis\seniors_allcourses.csv"
$_DestinationPath = "Z:\"
Copy-item –path $_SourcePath –destination $_DestinationPath -force
enter image description here

Powershell to unblock all the files in a folder

Trying to make a .bat I can drop in a folder, when run it will unblock all the files in that folder...
#ECHO OFF
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {get-childitem '%~dp0' | unblock-file}"
EXIT
...keeps telling me "The term 'unblock-file' is not recognized as the name of a cmdlet..." no matter how I try to format it, where am I going wrong?
I'm trying to do this so I can just copy the .bat to the folder (and NOT have to copy a .bat and .ps1) so I thought a 1-line powershell "call" was the way to go?
The unblock-file command is available from Powershell 3.0.
Upgrade your PowerShell and script should work
Tested and working:
dir -r | unblock-file
Unblocks everything from the current directory recursively

Powershell executing .exe file without the folder path

I am fairly new to powershell and I am trying to create a script that executes a .exe file. I can execute them on my machine no problem because the folder path is hard coded. The problem is that if I shift this script to another computer, the .exe it calls might be located in a different folder structure. Example
My computer:
D:\Folder1\subfolder\RunMe.exe
Client computer might be
D:\RunMe\subfolder\RunMe.exe
I just need it to execute the RunMe.exe no matter where it is. Is there a way to do this in powershell?
# 1. Get the location of RunMe.exe
$RunMe = Get-ChildItem -Path d:\* -Include RunMe.exe -Recurse;
# 2. Invoke RunMe.exe
Start-Process -FilePath $RunMe[0].FullName -Wait -NoNewWindow;

Powershell Copy-item command not working in script although it does work when run from a command line

I am on a Windows 7 machine trying to execute a PowerShell script to copy a template directory to another directory. The command I am executing looks like:
Copy-Item -path "$projectsFolder$SourceFolder" -destination "$Test" -recurse -verbose;
The parameters are as follows:
path: C:\Users\username\Documents\Visual Studio 2010\Projects\TemplateSolution\Source
Destination: C:\Users\username\Documents\Visual Studio 2010\Projects\test\source\main
When I run this command at a PowerShell prompt, the files are copied correctly. If I try and execute the command in the script with verbose enabled, it appears to copy the files and directories, but only the top level directory is created in the file system. I am not sure why this would happen and I would appreciate any guidance or troubleshooting steps to perform.
Make sure you put quotes around the directory names if they have spaces in them. Also, you may need the -Force parameter to create destination directories if they do not exist.