{"id":1592,"date":"2023-06-15T02:03:34","date_gmt":"2023-06-15T05:03:34","guid":{"rendered":"https:\/\/blog.abratel.com.br\/?p=1592"},"modified":"2023-06-15T02:04:25","modified_gmt":"2023-06-15T05:04:25","slug":"powershell-scripts-for-intune","status":"publish","type":"post","link":"https:\/\/blog.abratel.com.br\/?p=1592","title":{"rendered":"Powershell Scripts For Intune"},"content":{"rendered":"<p>endpoint.microsoft.com &#8211;&gt; Devices &#8211;&gt; scripts &#8211;&gt;<\/p>\n<p>Run this script using the logged on credentials<br \/>\nYes (some can be no)<br \/>\nEnforce script signature check<br \/>\nNo<br \/>\nRun script in 64 bit PowerShell Host<br \/>\nYes (some can be 32)<\/p>\n<p>Here I will rename a local admin to another admin changing the password:<br \/>\nrenameadm.ps1<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$oldUsername =  &quot;usertoremove&quot;\n$newUsername = &quot;newadministrator&quot;\n$oldPassword = ConvertTo-SecureString &quot;passwordforusertoremove&quot; -AsPlainText -Force\n$newPassword = ConvertTo-SecureString &quot;newpasswordfornewadm&quot; -AsPlainText -Force\n$user = Get-LocalUser -Name $oldUsername\nRename-LocalUser -Name $oldUsername -NewName $newUsername\nSet-LocalUser -Name $newUsername -Password $newPassword\n<\/pre>\n<p>Here I will remove all local admin and also azure admins\/users and leave just the local admin that I created:<br \/>\nremoving_all_adms_less_one.ps1<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$group = [ADSI]&quot;WinNT:\/\/$env:COMPUTERNAME\/Administrators&quot;\n$admins = $group.Invoke('Members') | ForEach-Object {\n$path = ([adsi]$_).path\n[PSCustomObject]@{\nUser = $(Split-Path $path -Leaf) }}\nforeach ($user in $admins) {\n$test = $user.User # Assign the user value to $test variable for comparison\nif ($test -eq &quot;keep-this-username-adm&quot;) {\n} else {\nRemove-LocalGroupMember -Group Administrators -Member $test }}\n<\/pre>\n<p>Here I&#8217;m removing the PIN<br \/>\nremovepin.ps1<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$path = &quot;HKLM:\\SOFTWARE\\Policies\\Microsoft&quot;\n$key = &quot;PassportForWork&quot;\n$name = &quot;Enabled&quot;\n$value = &quot;0&quot;\nNew-Item -Path $path -Name $key \u00e2\u20ac\u201cForce\nNew-ItemProperty -Path $path\\$key -Name $name -Value $value -PropertyType DWORD -Force\n#Delete existing pins\n$passportFolder = &quot;C:\\Windows\\ServiceProfiles\\LocalService\\AppData\\Local\\Microsoft\\Ngc&quot;\nif(Test-Path -Path $passportFolder)\n{\nTakeown \/f $passportFolder \/r \/d &quot;Y&quot;\nICACLS $passportFolder \/reset \/T \/C \/L \/Q\nRemove-Item \u00e2\u20ac\u201cpath $passportFolder \u00e2\u20ac\u201crecurse -force\n}\n<\/pre>\n<p>Here I will set a background image:<br \/>\nsetbackground.ps1<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$RegKeyPath = &quot;HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PersonalizationCSP&quot;\n$LockScreenPath = &quot;LockScreenImagePath&quot;\n$LockScreenStatus = &quot;LockScreenImageStatus&quot;\n$LockScreenUrl = &quot;LockScreenImageUrl&quot;\n$StatusValue = &quot;1&quot;\n$url = &quot;https:\/\/www.meusite.com\/wp-content\/uploads\/2023\/04\/wallpaper.png&quot;\n$LockScreenImageValue = &quot;C:\\MDM\\wallpaper.png&quot;\n$directory = &quot;C:\\MDM\\&quot;\nIf ((Test-Path -Path $directory) -eq $false)\n{\nNew-Item -Path $directory -ItemType directory\n}\n$wc = New-Object System.Net.WebClient\n$wc.DownloadFile($url, $LockScreenImageValue)\nif (!(Test-Path $RegKeyPath))\n{\nWrite-Host &quot;Creating registry path $($RegKeyPath).&quot;\nNew-Item -Path $RegKeyPath -Force | Out-Null\n}\nNew-ItemProperty -Path $RegKeyPath -Name $LockScreenStatus -Value $StatusValue -PropertyType DWORD -Force | Out-Null\nNew-ItemProperty -Path $RegKeyPath -Name $LockScreenPath -Value $LockScreenImageValue -PropertyType STRING -Force | Out-Null\nNew-ItemProperty -Path $RegKeyPath -Name $LockScreenUrl -Value $LockScreenImageValue -PropertyType STRING -Force | Out-Null\nRUNDLL32.EXE USER32.DLL, UpdatePerUserSystemParameters 1, True\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>endpoint.microsoft.com &#8211;&gt; Devices &#8211;&gt; scripts &#8211;&gt; Run this script using the logged on credentials Yes (some can be no) Enforce script signature check No Run script in 64 bit PowerShell Host Yes (some can be 32) Here I will rename a local admin to another&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1599,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts\/1592"}],"collection":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1592"}],"version-history":[{"count":4,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts\/1592\/revisions"}],"predecessor-version":[{"id":1601,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts\/1592\/revisions\/1601"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/media\/1599"}],"wp:attachment":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}