The example script imports the contents of a specified CSV file, loops through each computer, loops through each user profile on that computer and manipulates an ini file, if found, within any user profile on the device.
$Computers = Get-Content "\\server\some\share\computers.csv"
# Loop through computers
foreach ($computer in $computers)
{
Write-Host "Connecting to $computer"
$CheckComp = Test-Path "\\$computer\C$"
#If computer is offline
if ($CheckComp -eq $False)
{
Write-Host -fore Red "Can't contact $computer - is it online?"
sleep 1
#exit
}
#If computer is online
if ($CheckComp -eq $True)
{
# Grab the remote contents of C:\Users
$users = get-childitem "\\$computer\C$\Users\"
# Loop through the remote users and manipulate the .ini file
foreach ($user in $users)
{
$Path = "\\$computer\C$\Users\$user\AppData\Roaming\SomeApplication\LicenseDetails.ini"
$PathExists = Test-Path $path
if ($PathExists -eq $true)
{
(Get-Content $Path).replace('proxyUse=-1', 'proxyUse=-0') | set-content $Path
(Get-Content $Path).replace('proxyHost=proxy.some.company.com', 'proxyHost=') | set-content $Path
(Get-Content $Path).replace('proxyPort=8080', 'proxyPort=') | set-content $Path
write-host "$user's license file changed"
}
}
}
}
No comments:
Post a Comment