none
Add-Content in GPO Script won't work RRS feed

  • Question

  • Hi guys,

    I've a singolar issue here, bear with me, I'm not that good in scripting.

    I've set up a script that works fine, at the end of whom I need to generate or append a log file with some variables printed out into it.

    Strange enough, when i run the script manually or by the powershell ISE it works without issues, nevertheless, while in GPO at the logon of the user, everything works but the Add-Content.

    here the script part:

    if	($DHCPON -eq " True")
    		{
    $ip=(ipconfig | findstr IPv4 | %{ $_.Split(':')[1]; }	|%{ $_.Split(' ')[1]; })		
    netsh interface ipv4 set address name="$NAME3" static $ip 255.255.255.0 $GW 1
    netsh interface ip add dns $NAME3 IPADDR
    netsh interface ip add dns $NAME3 x.x.x.x index=2
    sendmail Send-MailMessage -SmtpServer 'IPADDR' -From 'User01 <user01@fabrikam.com>' -To 'User02 <user02@fabrikam.com>' -Subject 'Sending the Attachment' -Body "Forgot to send the attachment. Sending now."
    Add-Content \\IPADDR\Distribution\RunScriptGPO.csv "$ip,$env:computername"

    Any suggestion is really appreciated.

    Thanks,



    • Edited by GreyFloyd84 Wednesday, October 23, 2019 11:03 AM
    Wednesday, October 23, 2019 11:02 AM

All replies

  • This is a GPO issue. Post in the GPO forum to learn how to get logon scripts to function correctly.

    What you are trying to do should never be done in a logon script.  That is not what they are designed for and will not work as expected.

    You cannot change the IP or the network in a logon or startup script for obvious reasons.


    \_(ツ)_/

    Wednesday, October 23, 2019 3:52 PM
  • I’m with you, it should never be done, but this is a customer specific request. Nevertheless, it works as expected for what it is meant to do, with that said, I’ve solved the issue moving the Add-Content just below the first variable in the if condition. Thanks for the support.
    Wednesday, October 23, 2019 6:59 PM