I am new to powershell but learning more everyday it seem. I have been given a task to figure out how to perform software updates/upgrades using Powershell.
I have come up with a script but it is not working properly and need some help figuring out what is wrong with the script so I can get it to work or coming up with a script that will work.
Below is the script I am currently trying…
“”"Welcome to Orlando’s application deployment interface. Please select from the folowing
applications to deploy or uninstall.
VLC Media Player 3.0.11
Any App 2
More coming soon
…
“”"
$selection = Read-Host -Prompt "Please enter your selection: "
$targetComputer = Read-Host -Prompt "Enter target computer: "
$destination = "\$targetComputer\c$\temp"
When I run it and input the selections required the files get copied to the target computer as expected but the vbs scripts never run or I am getting the following error…
PS C:> D:\Installmsi.ps1
"Welcome to Orlando’s application deployment interface. Please select from the folowing
applications to deploy or uninstall.
VLC Media Player 3.0.11
Any App 2
More coming soon
…
"
Please enter your selection: : 1
Enter target computer: : amhraowintest16
Directory: \amhraowintest16\c$
Mode LastWriteTime Length Name
d----- 12/7/2020 10:52 AM temp
Press I to install or X to uninstall: I
Invoke-Command : The value of the using variable ‘$using:LocalPath’ cannot be retrieved because it has not been set in the
local session.
At D:\Installmsi.ps1:32 char:5
I think it might help if I explain what I am trying to accomplish before I answer that question.
The goal here is to use an installer (install.vbs) to install an application from a network share on a remote computer or remote computers.
So I believe the localPath should be the location that the content (e.g. install.vbs was copied to on the target machine).
I am running the script from my workstation to go out to a network share copy the content to a target machine (amhraowintest16). and then run the vbs script on that target machine.
I think it might help if I explain what I am trying to accomplish before I answer that question.
The goal here is to use an installer (install.vbs) to install an application from a network share on a remote computer or remote computers.
So I believe the localPath should be the location that the content (e.g. install.vbs was copied to on the target machine).
I am running the script from my workstation to go out to a network share copy the content to a target machine (amhraowintest16). and then run the vbs script on that target machine.
[/quote]
The only file I see copied to the machine is install.vbs. What other files are there? My guess is it needs to point to some share location, but need to understand what argument Install.vbs is looking for. Regardless you need to assign that location to LocalPath in order for it to work. Also, the if and else statements are doing the exact same thing. Not sure that is what you want right?
Below is the error after the files are copied to the remote computer…
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
Input Error: Can not find script file “C:\Users\myuserprofile\Documents\Install.vbs”.
Based on the error it looks like to me that it is trying to find the Install.vbs on my local machine under my userprofile\documents directory.
My question is where in the script does it tell it to launch the VBS script from my local machine and how can I tell it to launch it from the remote computer and correct path?
Did you write this code? The script block for your if statement is the exact same as the script block for your else statement. I think you are missing lots of basic coding issues. First, “=” is an assignment operator. I think your if statement is testing for equality not assigning a value. The comparison operator you need is “-eq” Here are a couple resources I’d recommend to get started. I’ll link to the online version, but all can be accessed via Get-Help. If you use Get-Help recommend using the -showwindow switch so you get all the documentation in a seperate/searchable window.
Mike to answer your initial question, no I did not write the code I barrowed it and made modification where I thought I needed to for it to do what I wanted.
Thanks for the links to resources this is what I truly need to learn more about PowerShell and to start getting to know it much better. I only know enough to be dangerous at this point but am eager to learn once pointed in the right direction.
My understanding of the If statement below
if (!(Test-Path $TMP)) {
New-Item -Path $TMP -ItemType Directory
}
was that we would be testing for the path defined in the $tmp variable and if it did not exist it would be created per the variable.
I was not expecting that part to make any assignment.
No worries. I teach PowerShell in my normal job and I tell my students that they should at least know what the script they are running is doing by being able to look at the code and explain it. Some may disagree with me on this point, but when you are running scripts across a operational network using administrator privileges, it is as you point out “dangerous” to not understand how the script works. Hopefully, you have a test environment or sandbox to try stuff out before operational employment.
You are not providing the literal path to the VBS file for cscript.exe so it is defaulting to the Desktop. That is my take on this. No way for me to test.
I made some tweaks to the script based on additional ways to do what I was trying to do and now I am getting a very different error. It makes me feel like I am getting closer but I am not good enough at Powershell “Yet” to understand if I am making progress or going backward.
Here is the new code and below that the new error.
PS C:\Users\raf03576> $Error
Invoke-Command : Missing an argument for parameter ‘ScriptBlock’. Specify a parameter of type
‘System.Management.Automation.ScriptBlock’ and try again.
At C:\Users\raf03576\Documents\InstallVLC3.0_V3.ps1:16 char:64
… mand -ComputerName “$Computer” -Credential $Cred -ScriptBlock -ErrorA …
Yes we do have a test environment that I use for testing and for the most part I (thought) I understood what the script was doing. I just was not 100% sure of how it was doing it.
However I agree with your stand on knowing what a script is suppose to be doing before running it.