I'm wondering if some can point our why the last line in the script is not running via my scheduled task, the task runs at logon and as the system account. the Line runs when I run it manually
I have also tried start-process instead of invoke-item
$username = Get-WmiObject -class Win32_ComputerSystem | select-object -ExpandProperty username
$username = $username.replace(Domainname\', '')
$FaxClientService = 'printclient'
$FaxClientexec = 'C:\program files (x86)\fax\client\bin\printclient.exe'
$WantFile = "c:\users\'+$username+'\appdata\roaming\fax\client\PrintToFaxUserSettings.xml"
$FileExists = Test-Path $WantFile
If ($FileExists -eq $true)
{
exit
}
Else
{
# Insert username into XML
$xml = new-object XML
$xml.PreserveWhiteSpace = $true
$xml.load("C:\temp\faxprinter\PrintToFaxUserSettings.xml")
$xml.usersettings.username = $username
$xml.PreserveWhiteSpace = $true
$xml.save("C:\temp\faxprinter\PrintToFaxUserSettings.xml")
Start-Sleep -s 10
$ErrorActionPreference = "SilentlyContinue"
Stop-Process -processname $FaxClientService -Force
$ErrorActionPreference = "Stop"
New-Item c:\users\$username\appdata\roaming\fax -type directory
New-Item c:\users\$username\appdata\roaming\fax\Client -type directory
$source = 'c:\temp\faxprinter\PrintToFaxUserSettings.xml'
$dest = 'c:\users\' + $username + '\appdata\roaming\fax\client\PrintToFaxUserSettings.xml'
Copy-Item -Force $source $dest
Start-Sleep -s 30
Invoke-Item $FaxClientexec
}
Invoke-Itemcommand. technet.microsoft.com/en-us/library/hh849794.aspx - Eric S