Hey everyone,
Not the best at writing these things… I feel like I have the right syntax down. If someone could help out that’d be great! Everything executes fine but doesn’t end up creating my scheduled task.
Param(
[Parameter(Mandatory=$True, Position=1)]
[string] $computernames,
[Parameter(Mandatory=$True, Position=2)]
[system.management.automation.PSCredential] $credential,
[Parameter(Mandatory=$True, Position=3)]
[String] $date,
[Parameter(Mandatory=$True, Position=4)]
[String] $time
)
foreach($server in $computernames){
Invoke-Command -cn $server -ScriptBlock { Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall* | select DisplayName}
foreach($Name in $server){
If($Name.DisplayName -like "Microsoft Office Office 64-bit Components 2007"){
Invoke-Command -Computer $server -Credential $credential -ScriptBlock {
param($date, $time)
schtasks /create /tn “Uninstall Office 2007” /tr “\Fileserver03\Install\Microsoft\Office\2007\setup.exe /uninstall ProPlus /config \Fileserver03\Install\Microsoft\Office\2007\SilentUninstall.xml” /sc Once /sd $date /st $time /f /V1 /z /ru System
} -ArgumentList $date, $time}
If($Name.DisplayName -like "Microsoft Office Professional Plus 2010"){
Invoke-Command -Computer $server -Credential $credential -ScriptBlock {
param($date, $time)
schtasks /create /tn “Uninstall Office 2010” /tr “\Fileserver03\Install\Microsoft\Office\2010\Uninstall\setup.exe /uninstall ProPlus /config \Fileserver03\Install\Microsoft\Office\2010\Uninstall\SilentUninstall.xml” /sc Once /sd $date /st $time /f /V1 /z /ru System
} -ArgumentList $date, $time}
If($Name.DisplayName -like "Microsoft Office 64-bit Components 2013"){
Invoke-Command -Computer $server -Credential $credential -ScriptBlock {
param($date, $time)
schtasks /create /tn “Uninstall Office 2013” /tr “\Fileserver03\Install\Microsoft\Office\2013\Admin\setup.exe /uninstall ProPlus /config \Fileserver03\Install\Microsoft\Office\2013\Admin\SilentUninstall.xml” /sc Once /sd $date /st $time /f /V1 /z /ru System
} -ArgumentList $date, $time}
}
}