<\/use><\/svg><\/div><\/a><\/div><\/p>","upvoteCount":1,"datePublished":"2013-11-05T16:50:22.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-powershell-script-please-assist/252898/4","author":{"@type":"Person","name":"chamele0n","url":"https://community.spiceworks.com/u/chamele0n"}},{"@type":"Answer","text":"Sorry TFL,<\/p>\n
My apologies, the whole script works. It’s just it only successful on 1 of 10 computers. I was receiving the error above, so I was just wondering if you guys have seen it before?<\/p>\n
THanks a million, and I know its way more than just a ask. If one feels up to it.<\/p>","upvoteCount":0,"datePublished":"2013-11-05T17:14:39.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-powershell-script-please-assist/252898/5","author":{"@type":"Person","name":"chrisromano8238","url":"https://community.spiceworks.com/u/chrisromano8238"}},{"@type":"Answer","text":"
Is this something you built or downloaded from the internet?<\/p>\n
I see a few things wrong with this script.<\/p>\n
Your functions are built totally wrong, your’s go:<\/p>\n
Function FunctionName {\n\tParam ([string]$Param1, $Param2, $Param3)\n}\n<\/code><\/pre>\nAnd they are missing a body (What the script actually does when you run the function)<\/p>\n
It should be in the following format:<\/p>\n
Function FunctionName\n(\n\t[string]$Param1,\n\t[string]$Param2,\n\t[string]$Param3\n)\n{\n\t#Script Body Here\n\t#Call some Parameters from Param field\n\t#Do other cool things.\n}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2013-11-05T17:15:22.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-powershell-script-please-assist/252898/6","author":{"@type":"Person","name":"chamele0n","url":"https://community.spiceworks.com/u/chamele0n"}},{"@type":"Answer","text":"Chamele0n,<\/p>\n
Thanks for the feedback. No, I attempted to develop this script on my own. I am definitely a newbie at powershell, so sorry if the function and string statements are incorrect. I kind of self-taught myself. Do you think this would be causing that error?<\/p>\n
Thanks again for the help.<\/p>\n
-Chris<\/p>","upvoteCount":0,"datePublished":"2013-11-05T17:20:56.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-powershell-script-please-assist/252898/7","author":{"@type":"Person","name":"chrisromano8238","url":"https://community.spiceworks.com/u/chrisromano8238"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Chrstphr:<\/div>\n
\nChamele0n,<\/p>\n
Thanks for the feedback. No, I attempted to develop this script on my own. I am definitely a newbie at powershell, so sorry if the function and string statements are incorrect. I kind of self-taught myself. Do you think this would be causing that error?<\/p>\n
Thanks again for the help.<\/p>\n
-Chris<\/p>\n<\/blockquote>\n<\/aside>\n
I’m scrolling back up but looks like you deleted a post. There was a post with some error messages, a lot of the messages stated “Function missing Body”…With that said, yes I would thing these functions would be causing some errors when running the scripts.<\/p>\n
Even if it is not causing the problem and it does run successfully. It would be good for you to fix them, just so that you learn the right way to do it.<\/p>","upvoteCount":1,"datePublished":"2013-11-05T17:26:59.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-powershell-script-please-assist/252898/8","author":{"@type":"Person","name":"chamele0n","url":"https://community.spiceworks.com/u/chamele0n"}},{"@type":"Answer","text":"
Chamele0n,<\/p>\n
Here are the messages I received.<\/p>\n
Missing expression after unary operator '+'.\nAt line:3 char:5\n\nMissing expression after unary operator '+'.\nAt line:4 char:5\n\nMissing function body in function declaration.\nAt line:146 char:6\n\nMissing function body in function declaration.\nAt line:154 char:2\n\nMissing function body in function declaration.\nAt line:160 char:2\n\nMissing function body in function declaration.\nAt line:214 char:2\n\nYou must provide a value expression on the right-hand side of the '=' operator.\nAt line:30 char:14\n\nMissing closing ')' after expression in 'while' statement.\nAt line:398 char:6\n\nMissing closing ')' after expression in 'while' statement.\nAt line:410 char:2\n\nMissing closing ')' in expression.\nAt line:415 char:3\n\nUnexpected token 'Write-Host' in expression or statement.\nAt line:415 char:3\n\nUnexpected token 'Waiting for $jobcount Jobs to Complete sleeping 5 seconds' in expression or statement.\nAt line:415 char:14\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2013-11-05T17:36:35.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-powershell-script-please-assist/252898/9","author":{"@type":"Person","name":"chrisromano8238","url":"https://community.spiceworks.com/u/chrisromano8238"}},{"@type":"Answer","text":"function InstallMSU {\n (\n [String]$strComputer, \n [String]$objFile,\n [String]$sysArch, \n [String]$antiarch\n )\n {\n<\/code><\/pre>\nSo something like this?<\/p>","upvoteCount":0,"datePublished":"2013-11-05T17:40:44.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-powershell-script-please-assist/252898/10","author":{"@type":"Person","name":"chrisromano8238","url":"https://community.spiceworks.com/u/chrisromano8238"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Chrstphr:<\/div>\n
\nfunction InstallMSU {\n (\n [String]$strComputer, \n [String]$objFile,\n [String]$sysArch, \n [String]$antiarch\n )\n {\n<\/code><\/pre>\nSo something like this?<\/p>\n<\/blockquote>\n<\/aside>\n
No, it should look like this:<\/p>\n
Function InstallMSU\n(\n\t[string]$strComputer,\n\t[string]$objFile,\n\t[string]$sysArch,\n\t[string]$antiarch,\n)\n{\n\t#Script Body Here\n\t#Call some Parameters from Param field\n\t#Do other cool things.\n}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2013-11-05T17:48:30.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-powershell-script-please-assist/252898/11","author":{"@type":"Person","name":"chamele0n","url":"https://community.spiceworks.com/u/chamele0n"}},{"@type":"Answer","text":"Okay guys, sorry for the late reply. I got the .msu part rolling well. Now I am stuck at the .msi part. As the .msu section I have multiple .msi in a folder. I want to run them quiet with no user interaction of course, but I cant figure out the correct WMICLASS cmd to get it rolling. The section of the code is below. Any help would be much appreciated. Thanks<\/p>\n
function InstallMSI \n{ param(\n [String]$strComputer, \n [String]$objFile, \n [String] $sysArch, \n [String]$antiarch\n )\n\n write-host \"\"\n write-host \"Security Installer\"\n write-host \"\"\n \n $MSIName = [string]$objFile.name\n $MSIExt = $objFile.extension\n $MSIFullName = $objFile.FullName\n $MSIProc = ($MSIName.trimend(\".msi\"))\n write-host $MSIProc\n \n $MSIProc = [string]$MSIProc\n \n if (($MSIName -Notmatch $sysArch) -and ($MSIName -match $antiarch))\n {\n return\n }\n \n if ($MSIName -match \"ia64\")\n {\n return\n }\n\n copy-item $MSIFullName \\\\$strComputer\\c$\\$MSIName -force\n \n $install = (([WMICLASS]\"\\\\$strComputer\\ROOT\\CIMV2:win32_process\").Create(\"cmd /c msiexec.exe /I c:\\$MSIName /qn /passive\")) \n \n start-sleep -Seconds 5\n \n $MSItest = get-process -cn $strComputer -name \"$MSIProc\"\n \n while ($MSItest -ne $null)\n {\n start-sleep -seconds 1\n write-host \"waiting for MSI install to complete\"\n $MSItest = get-process -cn $strComputer -name \"$MSIProc\" \n \n }\n\n }\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2013-11-14T19:14:58.000Z","url":"https://community.spiceworks.com/t/need-assistance-with-powershell-script-please-assist/252898/13","author":{"@type":"Person","name":"chrisromano8238","url":"https://community.spiceworks.com/u/chrisromano8238"}}]}}
DoctorDNS
(DoctorDNS)
November 5, 2013, 4:05pm
2
Sorry - but that script is way beyond a reasonable ask.
I suggest you post a much shorter sample (thsat’s not working). Of course, I do debugging like this for my clients every day!
Also - you are doing some very convoluted things, for example:
$install = (([WMICLASS]“\$strComputer\ROOT\CIMV2:win32_process”).Create(“cmd /c md c:$msuFolder”))
start-sleep -seconds 1
WHy not just:
Invoke-Command -computer XXX -ScriptBlock {Md c:$msuolder} -credentials $Cred
2 Spice ups
hs13
(hs13)
November 5, 2013, 4:14pm
3
What line did it throw the error?
chamele0n
(Chamele0n)
November 5, 2013, 4:50pm
4
In your error you did not post the entire error, looks like you just posted the “Invalid Parameter” section and not the information about what line is failing.
We need more information please.
Also, please remember when posting code to use the code button and select “Powershell” in this case (It makes it much easier to read)
1 Spice up
Sorry TFL,
My apologies, the whole script works. It’s just it only successful on 1 of 10 computers. I was receiving the error above, so I was just wondering if you guys have seen it before?
THanks a million, and I know its way more than just a ask. If one feels up to it.
chamele0n
(Chamele0n)
November 5, 2013, 5:15pm
6
Is this something you built or downloaded from the internet?
I see a few things wrong with this script.
Your functions are built totally wrong, your’s go:
Function FunctionName {
Param ([string]$Param1, $Param2, $Param3)
}
And they are missing a body (What the script actually does when you run the function)
It should be in the following format:
Function FunctionName
(
[string]$Param1,
[string]$Param2,
[string]$Param3
)
{
#Script Body Here
#Call some Parameters from Param field
#Do other cool things.
}
1 Spice up
Chamele0n,
Thanks for the feedback. No, I attempted to develop this script on my own. I am definitely a newbie at powershell, so sorry if the function and string statements are incorrect. I kind of self-taught myself. Do you think this would be causing that error?
Thanks again for the help.
-Chris
chamele0n
(Chamele0n)
November 5, 2013, 5:26pm
8
Chrstphr:
Chamele0n,
Thanks for the feedback. No, I attempted to develop this script on my own. I am definitely a newbie at powershell, so sorry if the function and string statements are incorrect. I kind of self-taught myself. Do you think this would be causing that error?
Thanks again for the help.
-Chris
I’m scrolling back up but looks like you deleted a post. There was a post with some error messages, a lot of the messages stated “Function missing Body”…With that said, yes I would thing these functions would be causing some errors when running the scripts.
Even if it is not causing the problem and it does run successfully. It would be good for you to fix them, just so that you learn the right way to do it.
1 Spice up
Chamele0n,
Here are the messages I received.
Missing expression after unary operator '+'.
At line:3 char:5
Missing expression after unary operator '+'.
At line:4 char:5
Missing function body in function declaration.
At line:146 char:6
Missing function body in function declaration.
At line:154 char:2
Missing function body in function declaration.
At line:160 char:2
Missing function body in function declaration.
At line:214 char:2
You must provide a value expression on the right-hand side of the '=' operator.
At line:30 char:14
Missing closing ')' after expression in 'while' statement.
At line:398 char:6
Missing closing ')' after expression in 'while' statement.
At line:410 char:2
Missing closing ')' in expression.
At line:415 char:3
Unexpected token 'Write-Host' in expression or statement.
At line:415 char:3
Unexpected token 'Waiting for $jobcount Jobs to Complete sleeping 5 seconds' in expression or statement.
At line:415 char:14
function InstallMSU {
(
[String]$strComputer,
[String]$objFile,
[String]$sysArch,
[String]$antiarch
)
{
So something like this?
chamele0n
(Chamele0n)
November 5, 2013, 5:48pm
11
Chrstphr:
function InstallMSU {
(
[String]$strComputer,
[String]$objFile,
[String]$sysArch,
[String]$antiarch
)
{
So something like this?
No, it should look like this:
Function InstallMSU
(
[string]$strComputer,
[string]$objFile,
[string]$sysArch,
[string]$antiarch,
)
{
#Script Body Here
#Call some Parameters from Param field
#Do other cool things.
}
1 Spice up
martin9700
(Martin9700)
November 6, 2013, 2:01pm
12
If you’re looking to have named parameters in a Function, the proper syntax is:
Function InstallMSU
{ Param (
[string]$strComputer,
[string]$objFile,
[string]$sysArch,
[string]$antiarch
)
#Script Body Here
#Call some Parameters from Param field
#Do other cool things.
}
2 Spice ups
Okay guys, sorry for the late reply. I got the .msu part rolling well. Now I am stuck at the .msi part. As the .msu section I have multiple .msi in a folder. I want to run them quiet with no user interaction of course, but I cant figure out the correct WMICLASS cmd to get it rolling. The section of the code is below. Any help would be much appreciated. Thanks
function InstallMSI
{ param(
[String]$strComputer,
[String]$objFile,
[String] $sysArch,
[String]$antiarch
)
write-host ""
write-host "Security Installer"
write-host ""
$MSIName = [string]$objFile.name
$MSIExt = $objFile.extension
$MSIFullName = $objFile.FullName
$MSIProc = ($MSIName.trimend(".msi"))
write-host $MSIProc
$MSIProc = [string]$MSIProc
if (($MSIName -Notmatch $sysArch) -and ($MSIName -match $antiarch))
{
return
}
if ($MSIName -match "ia64")
{
return
}
copy-item $MSIFullName \\$strComputer\c$\$MSIName -force
$install = (([WMICLASS]"\\$strComputer\ROOT\CIMV2:win32_process").Create("cmd /c msiexec.exe /I c:\$MSIName /qn /passive"))
start-sleep -Seconds 5
$MSItest = get-process -cn $strComputer -name "$MSIProc"
while ($MSItest -ne $null)
{
start-sleep -seconds 1
write-host "waiting for MSI install to complete"
$MSItest = get-process -cn $strComputer -name "$MSIProc"
}
}