Quantcast
Channel: PowerShell
Viewing all 15370 articles
Browse latest View live

PowerShell and RegEx Cookbook for 1$


Powershell: Delete User Folders AppData Denied Access

$
0
0

I'm sure this is a pretty common issue but I'm simply trying to delete all user accounts from this array of usernames to remove (excluding the current user, public, admin, etc...) I want to completely remove the folder after the account is deleted and whilst the account part works fine, the Local AppData folder seems to be denying me access to delete it. I've got -force and -recurse on the go and have tried with/without them. Here's the function. Also, bare in mind it works fine but just can't access the AppData side of things.

Powershell
functiondelFolder($arrDelFolders){foreach($itemin$arrDelFolders){$filePath="C:\Users\$item"Remove-Item$filePath-Force-Recurse-ErrorActionSilentlyContinueif(Test-Path$filePath){Write-Output"$tab DELETE-FOLDERS: Unable to Delete Folder: $item"|Add-Content$outLogPath-PassThru}else{...

Delete Profiles Script Expect

$
0
0

Triedsearching and not found what I was needing, hoping someone super kind could help me with a long dilemma.

We only use folder redirectionfor staff and for Students at our school, There files are only stored on the computer' drive. At the moment every month or two I have to login into each machine and go to this pc right click advanced blah, and delete each profile manually, which is very time-consuming.

I found the GPO for this that deleted pofileswhich works however it also delete a few profiles that need to remain, Admin and local admin ECT.. not sure what there needed for as not learn'tthis but remember my IT manager mentioned this some time ago (since left) - so guess would be best to get a script that deletes profiles apart from the profiles and then do this via schedule task.

however have no knowledge on scripting and do not have...

GetAD Users NOT in a list of security groups

$
0
0

Good morning everyone! I'm trying to do some maintenance in our AD environment, and disable a bunch of accounts that have not been in use in over 35 days. The trouble I'm having is trying to define some specific criteria to include, and other criteria to exclude.

I found the below script that someone else here in Spiceworks shared, and it worked great. But when I tried to add -and ([string]$_.memberOf -NotLike "*Domain Users*") to the script, I found that the script is not excluding members of the Domain Users security group:

Powershell
$OU="DC=contoso,DC=com"Get-ADUser-Filter{Enabled-eq$TRUE}-SearchBase$OU-PropertiesName,SamAccountName,LastLogonDate,DistinguishedName|Where{($_.LastLogonDate-lt(Get-Date).AddDays(-35))-and($_.LastLogonDate-ne$NULL)-and([string]$_.memberOf-NotLike"*Domain Users*")}|Sort|Select...

Powershell Script Errors

$
0
0

I have been following the Microsoft guide for setting up AlwaysOnVPN and having problems running the following script.

https://docs.microsoft.com/en-us/windows-server/remote/remote-access/vpn/always-on-vpn/deploy/vpn-de...

I have customised the custom elements at the start but i am getting the following errors any one got any ideas.

Text
At C:\build\MakeProfile.ps1:47 char:48 + $ProfileNameEscaped = $ProfileName -replace ' ', '%20' +                        ~~~~ Unexpected token '', '' in expression or statement. At C:\build\MakeProfile.ps1:47 char:53 + $ProfileNameEscaped = $ProfileName -replace ' ', '%20' +                          ~ You must provide a value expression following the '%' operator. At C:\build\MakeProfile.ps1:47 char:53 + $ProfileNameEscaped = $ProfileName -replace ' ', '%20' +                          ~~~ Unexpected...

Robocopy detects files as modfied

$
0
0

Recently moved a data set from a SAN presenting as a cifs to a windows server with a simple folder share. We have a robocopy task to mirror the data set to an identical windows server at another site nightly. Both servers are 2016 with the data set on a dedicated drive and have shadow copies enabled. The robocopy task runs from a third 2016 server. The command effective command is

Text
 Source : Dest : Files : *.* Exc Files : Thumbs.db *.lock ~* *.DS_Store Exc Dirs : System Volume Information *RECYCLE.BIN *DfsrPrivate* ~* Options : *.* /TBD /FFT /FP /NDL /S /E /DCOPY:DA /COPY:DATSO /PURGE /MIR /ZB /NP /XJ /R:0 /W:0 

The problem, is that if anyone opens a file and then closes it, robocopy detects it as "modified" and then performs a copy of the modified file to the mirror destination. I can't see any attributes that are changed from...

Powershell Command or Script to Download a PST File

$
0
0

Hello All,

Is there a way using powershell to export a users mailbox to a PST file?  We currently use eDiscovery in the Exchange Admin center to accomplish this.  I am wondering if there is a powershell way?

Audio Driver Swap - Scriptable?

$
0
0

Would it be possible to convert the steps below to a powershell script?  If so, could someone point me to a guide or an example that is similar that I could reverse engineer?

Open Device Manager

Go to Sound, video and game controllers

Find Realtek AudioRight-click, then click update driver.

Select "Browse my computer for driver software"

Click on "Let me pick from a list..."

Find the device "High Definition Audio Device"


Clearing Cache/Cookies/History from All Browsers

$
0
0

Fellow Spiceworks folks

Am looking for some help. I came across a script that supposedly cleans up all browser data (Cookies/Cache/History/Saved Forms, Passwords) from a log on user (IE/FireFox/Chrome). I ran it on a test computer but I find that it does not clear cookies from Chrome.

We have some users that try entering a new password on a site but it keeps remembering the old one. They have saved the information into the browser. Rather than have to visit them and/or remote to their PC, we would deploy the script to kill all browsers they have open, do the full clear of the above and have them go back in. The environment is a Windows 7 Pro x64 and the latest versions of IE, Firefox and Google Chrome. What we do not want to do is use GPO on login/logout nor use CCleaner portable.

This is the PS script I came across:

Powershell
Write-Host...

Need Help Setting Up SSL Certificate for RESTful Endpoint with Powershell

$
0
0

I'm trying to set up an SSL endpoint on my server (Windows Server 2012 R2) so that it can receive https POSTs from an external server. I am using a simple REST framework for Powershell called RestPS: https://github.com/jpsider/RestPS to listen on port 8089 and I have an SSL certificate that I'm trying to use but I am getting errors when I try to use it. I'm very much a novice with SSL certificates and need some help. When I run Start-RestPSListener in Powershell, I get these messages:

SSL Certificate deletion failed, Error: 2
The system cannot find the file specified.

SSL Certificate add failed, Error: 1312
A specified logon session does not exist. It may already have been terminated.

Starting: https:// Listener on Port: 8089

I'm not sure what those errors mean or if they matter. But something isn't right because when I try to POST from the...

I am looking for help with Microsoft Exchange PowerShell.

$
0
0

I am looking for help with Microsoft Exchange PowerShell. I have customer requesting we delete all emails older then 2 years in just 1 folder for just 1 user.  

Power Shell loop for each ip address

$
0
0

Hey so i have a working code(s) that needs to be run on multiple pc's from a text or csv file. By Ip address. Any help would be appreciated. I need to turn these off (wmi / F&P Sharing) to be able to run another ps file to check windows activation. I have a feeling it has to do with the variable $IP but im still in the learning process.

Powershell
ForEach($IPinGet-Content"input.txt")Invoke-Command{netshadvfirewallfirewallsetrulegroup="windows management instrumentation (wmi)"newenable=yes}

Adding AD module to a Windows 10 1809 PC

$
0
0

I think i am getting my self muddled on what i need,

I have a Windows 10 PC that is on 1809, I need to run PowerShell scripts that will pull info from AD so i need the AD module installed.

How do i do this?

Is the PowerShell AD module separate to the AD tools which i don't really want on the PC or are they part of the same package?

Thanks

Scripting Help

$
0
0

Hopefully there is a scripting guru out there that can help me.

I am doing some contract work for an attorney's office and they want to move several folders over.

Currently all case related material is listed under the individual attorney's folder, the folders are labeled Last Name, First Name

They want to move all the case information into a new folder share that has folders setup by First Letter of Last name, for example, there is a folder A-B, folder, C-D, folder E-F, etc etc.

So the order of moving would look like this

current location:

\\FileShare\AttorneyName\ClientLast Name, Client First Name

New Location

\\FileShare\Clients\K-L

Can anyone help with a script to move each of these folders over and keep the file permissions? I've done basic scripting before so any help with this would be greatly appreciated, otherwise I'll have to robo...

Power shell loop via txt help

$
0
0

Hey so i have a working code(s) that needs to be run on multiple pc's from a text or csv file. By Ip address. Any help would be appreciated. I need to turn these off (wmi / F&P Sharing) to be able to run another ps file to check windows activation. I have a feeling it has to do with the variable $IP but im still in the learning process.

Powershell
ForEach($IPinGet-Content"input.txt")Invoke-Command{netshadvfirewallfirewallsetrulegroup="windows management instrumentation (wmi)"newenable=yes}

Powershell Office 365 password custom smart lockout

$
0
0

I'm new to the scripting world but is there a script out or is it even possible to set the up "the lockout threshold for an Office 365 E-mail account"? We had an info e-mail account that was hacked and we didn't received an e-mail or any notification that a brute force attack had taken place. I know M/S Azure has the following menu "Azure has AD Security" Custom smart lockout with all of the options. But it's greyed out. I'm have placed a support ticket with M/S to see if the issue is with our subscription. Until, I can find out, I wanted to know if I can script this out.

run script from DC on servers listed in txt file, exempt users based on 2nd .txt

$
0
0

I want a script to log off any disconnected remote desktop sessions (not idle, but when they close their session window without logging out). I have a script, shown below, which works on any particular server it is ran on. So I *could* put this script on each server and have it run through task scheduler.

I would prefer to have it run once, on the DC, and run the script once for each server listed in a text file. Furthermore, I would like to be able to have a text file of user names, so that if a disconnected session is from one of the users listed, that session will be exempt from being logged off.

I don't know how to read things from a file or run the script multiple times. The script I have, I found online and modified slightly to get where I'm at now.

Here's what I have:

Text
$hostn = get-content env:computername $pc = qwinsta...

Powershell to enable bitlocker and save key in network share

$
0
0

Hi All,

I am sure its somewhere but i haven't been able to find what i am looking for

I am looking to enable bit locker and save the key with the host name in a shared network drive

Ideally id like to do this where i can insert my credentials for the network share as its an IT share, then after i can add in the power shell to disconnect from the network share after the upload of the recovery key is complete

I want to run this on remote users that will be on VPN to connect to the network share

Any help is greatly appreciated

Powershell to enable bitlocker and save key in network share

$
0
0

Hi All,

I am sure its somewhere but i haven't been able to find what i am looking for

I am looking to enable bit locker and save the key with the host name in a shared network drive

Ideally id like to do this where i can insert my credentials for the network share as its an IT share, then after i can add in the power shell to disconnect from the network share after the upload of the recovery key is complete

I want to run this on remote users that will be on VPN to connect to the network share

Any help is greatly appreciated

return values from workflow parallel

$
0
0

hi all,

trying to figure this one out... i want to create a workflow that will get some data from servers in parallel and return a variable with that data so i can use it further down the script (outside of the workflow)

here's what i have so far:

Powershell
Import-ModuleRemoteDesktopworkflowwf_LoadSessionHost_RDSHDataLIVE{$broker="broker.domain.local"$RDSHDataLIVE=@()$wmiNamespace="root\cimv2\rdms"$wmiRDSHServerQuery="SELECT * FROM Win32_RDSHServer"foreach-parallel($RDSHin(Get-WmiObject-Namespace$wmiNamespace-Query$wmiRDSHServerQuery-PSComputerName$broker-PSAuthenticationPacketPrivacy)){#$result = InlineScriptInlineScript{write-host"$($using:RDSH.name)"if(Test-Connection-ComputerName$using:RDSH.Name-Count1-Quiet){If((Get-WmiObject-Class"Win32_TerminalServiceSetting"-Namespace"root\CIMV2\...
Viewing all 15370 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>