Hot answers tagged

6

First of all, you had some typos in your code. The individual object of a list within a where-clause is addressed by $_, not $. And you were thinking around the corner. Your approach was a little complicated. Try this instead :) Get-ChildItem Z:\ -Recurse | where { $_.GetAccessControl().Owner -eq "DOMAIN\username"} | Remove-Item Although personally, I ...


5

As you've found, the instanceType attribute is marked "system-only", since you could potentially mess with the replication state of the directory replica in which you modify this attribute. You probably shouldn't be doing this! To circumvent this protection, add the following registry value on a Domain Controller: Key: ...


5

Group membership changes are not classified for urgent replication so it is normal to see the delay. Maybe you can use the -Server switch to point to the same DC that you are viewing in ADUC and you will be able to view the change instantly.


3

You might use a WMI query to get AccountType (512 = Enabled, 514 = Disabled): Edit: there are other flags which indicate enabled accounts, but the basic enabled/disabled is 512/514. Refer to this list. Third try: Function Check-Enabled ($Username) { -not (Get-WmiObject Win32_UserAccount -filter "LocalAccount=True AND Name='$Username'").disabled } ...


3

After a user account object is deleted, the SID will be removed from all groups the object was a member of. That is the reason why I personally prefer to disable user accounts, instead of deleting them. However, if you enabled the Active-Directory Recycle Bin feature, you will be able to restore the user account object and all group membership information ...


2

$msbuild = "${env:ProgramFiles(x86)}" + '\MSBuild\14.0\Bin\MSBuild.exe' Try this way. No spaces, so path should be fine.


2

Perhaps try using the the Call operator (&) instead of invoke-expression? I'm not sure how any output will be processed though. $solution = "test.sln" $msbuild = "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" Exec { & $msbuild $solution /t:clean} Exec { & $msbuild $solution }


2

Have you looked at creating an OnStart scheduled task? SCHTASKS.EXE /CREATE /F /SC ONSTART /RU Administrator /RP password!!! /TN "First Boot" /RL HIGHEST /TR "Powershell.exe -ExecutionPolicy Bypass -File C:\FirstBoot\FirstBoot.ps1 " You do need to have a command at the end of the script to remove this task SCHTASKS.EXE /DELETE /F /TN "First Boot"


2

That executable from MS appears to just be a self extracting archive (I was able to open it with 7-Zip). Have you tried unzipping the .exe somewhere and then attempting the /q switch on the Setup.exe contained within?


2

You can't check anything at all after a user account is deleted, because then AD no longer has any information about it; your only option is to check group membership (or any other info you might need) before deleting the user account.


1

The problem was that powershell has a default remote shell memory limit of 150MB. The install of .NET 4.6.1 would load the self-extracting exe's contents into memory, some items which were > 150 MB. This link provided the correct method to increase the memory limit. ...


1

This should work regardless of how many sub folders are in the path: $result = $ItemDirectory While (($result -split '\\' | ? { $_ }).Count -gt 3) { $result = Split-Path $result -Parent } $result


1

Please avoid using both single and double quotes, e.g. '"string"' $computer = 'abc01.somenetwork.net' Get-DnsEntry $computer or $computer = "abc01.somenetwork.net" Get-DnsEntry $computer Both should work fine.


1

I was finally able to get the script to work. The script was being run however it failed when it attempted to make a call to the Active Directory. The solution was to add the Active Directory module to Powershell. I found the instructions on how to do that here. I also added set-executionpolicy remotesigned and import-module activedirectory to the top of ...


1

Contents within single quotes are literal, variables are not expanded. Use double quotes on things that contain vars and need expansion. Replace the single quotes on the outside of your filter with double quotes. Used escaped double quotes (backtick double quote) on the inside for that parts with vars. You can use single quotes on the inside for params that ...


1

To perform a powershell search of all users with the msExchRecipientTypeDetails equal to 2, the following should get you started Import-module ActiveDirectory get-aduser -filter 'name -like "*" -properties * | where{$_.msExchRecipientTypeDetails -eq 2} | select distinguishedname,msExchRecipientTypedetails | Export-csv LinkedMailboxes.csv You might want to ...


1

This was actually a very silly issue. The steps you should be taking when adding a new rule to a security group: Get the security group using Get-AzureRmNetworkSecurityGroup Add the new RuleConfig using Add-AzureRmNetworkSecurityRuleConfig Set the new security group in Azure (IE publish it) using Set-AzureRmNetworkSecurityGroup My lack of comprehending ...


1

The shell may be eating your quotes, since both error message show them to be absent. {fusion_**** : *** } isn't valid JSON, it definitely needs to be {"fusion_****" : "***"} with both key and value quoted (assuming the value is a string; the literals true, false, and null... and numeric values are not quoted, of course). I would guess that it needs to be ...


1

when you use select-object, it returned an array of objects. Use below instead: $members = get-ADGroupMember foreach ($member in $members){write-host $member.samAccountName}


1

Actually the difference is much smaller if you use the same $_ in both tests. I didn't investigate the cause, but I suppose it's because the author is not using the same approach in both tests. Also, console output can interfere in the results. If you cut these parts, the numbers are very similar. See: Function AddOneFunction { process { $_ + ...


1

You can try setting the warning action before running the command: $oldWarningPreference = $WarningPreference $WarningPreference = 'SilentlyContinue' set-mailbox -Identity user@company.com -CustomAttribute6 knruiz@nfp.com -ErrorAction SilentlyContinue $WarningPreference = $oldWarningPreference


1

I could not solve the original problem with the CimInstance adding the value "". However, I did manage to get this to work by switching to an WmiObject: # Get Wmi object $smtpInstance = Get-WmiObject -Namespace root\MicrosoftIISv2 -ComputerName localhost -Query "Select * From IisSmtpServerSetting" # Set relay IP of 127.0.0.1 $relayIPs = @( 24, 0, 0, 128, ...


1

Here is the sudocode you could use. Sudocode means a basic idea of the logic in English, you'll need to do some research and lookup commands but this should help you get started # Get List of employees and their attributes using Get-ADUser # Loop over that list of employees using ForEach-Object ## Pull out information about the attributes you need ## Change ...


1

You requested Powershell so here you go. Just change the C:\Folder to wherever you need. This script will get a list of folders in the root, then a list of files/folders in those folders and delete them. Get-ChildItem -path C:\Folder\ | ?{ $_.PSIsContainer } | Foreach-Object{ $_ | Get-ChildItem -Recurse | Remove-Item } This can be expanded. Say I ...


1

You can start by exporting a detail report to a text for more detail Get-MailboxExportRequest -status failed | Get-MailboxExportRequestStatistics -IncludeReport | Format-List > c:\report.txt I hope your report will shed light on details of the failure


1

Are you determined to continue using WMIC? If you're using powershell you may find it more useful to use the native powershell cmdLets to obtain the same information. Depending on what you're doing with the file, this may allow you to skip the file. You could also pipe the WMI query results to | foreach { } get-wmiobject Win32_NetworkAdapter -filter ...


1

From Exchange Management Shell: If the mailbox does not exist on-premises nor in O365, then you need to use Enable-RemoteMailbox instead. Run this against an existing AD object on-prem. Technet reference: Enable-RemoteMailbox (EX2010) If the mailbox exists on-premises and you need to move it to the Cloud, use New-MoveRequest. This is a cross-forest move, ...



Only top voted, non community-wiki answers of a minimum length are eligible