Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

Need to delete the files in a folder whose size is 0KB

$
0
0

Hi Everyone,

I've a requirement where the I've to delete the contents of a folder which is of size 0kb. There are multiple files with varying size but only the 0kb files has to be deleted.

Please help me with the correct code for this.

Regards,

Manhoj


Create a Partition from remaining space of Virtual disk

$
0
0

Hi there

I created a storage Pool, then a Virtual disk off of the storage Pool, then a partition that is half the size of the virtual disk. All went smoothly with the following command:

Get-VirtualDisk "vDisk0" | Initialize-Disk -passthrough | New-Partition -AssignDriveLetter -Size 100Gb | Format-volume 

When i tried to do the same for a second Partition on the same virtual disk vDisk0 (to use all available space with the switch -UseMaximunSize) i get an error.

Can someone point to the right direction on how to create another partition from available free space of a virtual disk?

Thank you in advance.

How to remotely check if update is installed if I got "The RPC server is unavailable" ?

$
0
0

Hi there,

I wanted to use PowerShell to remotely check if update is installed.

I tried by using get-hotfix but for most computers (which are online and pingable) I got "The RPC server is unavailable."

How can I check for this computers for which I got "The RPC server is unavailable." ?

Is there another method to do so ?



copying Office365 group members to another Office365 group

$
0
0

I was hoping it was something this simple:

PS C:\scripts> $list = Get-UnifiedGrouplinks -Identity "OriginalGroup" -linktype members | fl emailaddresses
PS C:\scripts> Add-UnifiedGroupLinks -Identity "NewGroup" -LinkType Members -Links $list

This would have been easy if the default for creating groups was the Distribution List, but the Office365 groups don't use the same Powershell code.

Get-ADObject: A parameter cannot be found that matches the parameter name 'identity'

$
0
0

I'm using Windows 2012R2 with PS version 5.1.14409.1012 to execute scripts. Sometime in the last couple of weeks a script started failing that uses Get-ADObject -identity <variable containing user or group DN>. The cmdlet appears to no longer include an 'identity' parameter. 

Get-ADObject -identity on this computer gives me: A parameter cannot be found that matches the parameter name 'identity'

While the same command on a Windows 2008R2 PS v4.0 accepts that parameter and functions properly--and as stated, the 2012R2 was working as well, until sometime in the last few weeks.

Anyone know what's going on here?

 

Tony Auby

Uncomment a tag in web.config

$
0
0

Dear All,

I have a tag in web.config like this

<assemblies>
<!--<add assembly="Telerik.Reporting, Version=4.2.10.1221, Culture=neutral, PublicKeyToken=A9D7983DFCC261BE" />-->
</assemblies>

I need a powershell  script that can uncomment this tag.

Any help would be greatly appreciated

How to write a script to kill a process

$
0
0

in my windows server , there is a process is always crash and running with high memory

I just would like to write a script to kill the process which the process name is "orati" , would suggest how to write such script ?

PowerShell script for copying dll's

$
0
0

Hi,

I need a Powershell script to copy only certain DLL's from one folder to another folder on the Windows Server. Please let me know.

Thanks,


info2m


PowerShell Script to delete 100+ local user accounts from 50+ desktops

$
0
0

Hi,
I am looking for a power shell script to delete 100+ Local user accounts from 50+ desktops that are in the Domain. Instead of logging into each individual PC's, I prefer to run a power shell script from somewhere like the domain controller.

I have the details in an excel spreadsheet as below

hxxp://img292.imagevenue.com/loc19/th_099541774_PowerShell_122_19lo.JPG[/IMG

Please replace hxxp with http

Appreciate any help in this regard...



looking for a script to batch change Word file attributes like, label, category, manager, etc. without changing the last modification date?

$
0
0
I am not a programmer and try to find something to reuse. The script should go through a directory and sub directories. I want to use it for Word, Excel and PowerPoint both *.doc and *.docx formats. 

New-AzureRmResourceGroupDeploymen

$
0
0

<g class="gr_ gr_21 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="21" id="21"><g class="gr_ gr_25 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="25" id="25">i</g>'mtrying</g> to provision resources using ARM The template and <g class="gr_ gr_22 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="22" id="22">powershell</g> <g class="gr_ gr_24 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="24" id="24">was</g> running <g class="gr_ gr_23 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="23" id="23">smooth</g> a few days ago. Since <g class="gr_ gr_20 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="20" id="20">friday</g> I'm facing this error. I'm <g class="gr_ gr_30 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="30" id="30">pasing</g> all required arguments. 


New-AzureRmResourceGroupDeployment : 03:25:57 PM - Resource microsoft.insights/webtests/nkwebtest failed with '{
  "code": "BadRequest",
  "message": "Bad Request",
  "innererror": {
    "diagnosticcontext": "7df65c55-****-****-****-****29d2****",
    "time": "2018-10-08T09:55:56.226423Z"
  }
}'
At line:6 char:1
+ New-AzureRmResourceGroupDeployment -ResourceGroupName "nkwebtestRG" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

GetAzureRmMetric command is failing when getting executed on Windows 2016 powershell

$
0
0

Hi Team,

I have a script which is fetching metric data for azure resource, lets say, SQL Data warehouse.

It works fine when running on Windows 2012 machine with any timegrain value given for GetAzureRmMetric API.

I used the same script on windows 2016 machine and it failed with an error :

Exception type: ErrorResponseException, Message: Microsoft.Azure.Management.Monitor.Models.ErrorRespons
eException: Operation returned an invalid status code 'BadRequest'
   at Microsoft.Azure.Management.Monitor.MetricsOperations.<ListWithHttpMessagesAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.Monitor.MetricsOperationsExtensions.<ListAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Commands.Insights.Metrics.GetAzureRmMetricCommand.ProcessRecordInternal()
   at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet(), Code: Null, Status code:Null, Reason
 phrase: Null

Then I gave the timegrain as 1 hour in GetAzureRmMetric API and it worked but when I use any other value in timegrain, it fails.

Please help.

All computers with not existing registry path

$
0
0

Hi,

I try to get all computer list in AD domain which have NOT a specific registry path. The code is like below:

$server = get-adcomputer -filter * | select dnshostname  
foreach ($server in $servers) { 
 $registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $server)         
 $regKey= $reg.OpenSubKey("HKEY_LOCAL_MACHINE\SOFTWARE\myAPP\App1")      
 if ($regKey -eq $null){ $server } 
 }
$server |Export-Csv C:\ServerList.csv -NoTypeInformation 

Unfortunately, this lists all computers. When I change the if statement option from "-eq" to "-ne" there is no change in the result.

How can I do this statement and list these computers?

Best regards

Birdal

Script to only move files one at a time.

$
0
0

Hi, I'm trying to build a script that will only move 3 files at a time from a directory that may contain dozens of files.  I'll use the Windows scheduler to run the PowerShell script every 5 minutes.  So every 5 minutes 3 files will be moved.

I built the following PowerShell script that loops 3 times, but it moves all files at once.  What do I need to do to only copy one file at time during each of the 3 loops?  I can use either a PowerShell script or a batch file.

for($i = 0; $i -le 3; $i++)
{
get-childitem -path E:\test\TEST1\ -filter *.* | move-item -destination E:\test\TEST2
}

Clone Windows 10

$
0
0
Does Powershell have ability to CLONE current Windows 10 disk to an external USB disk as a backup? Thanks

Some Storage CMDLets do not work under WinPE

$
0
0

I have built a custom WinPE based on W2012 and included Powershell and a number of the Powershell CMDLets such as SMB, DISM, and Storage. Everything works fine. When you boot the WinPE disk and do a get-command -module Storage, it shows all of the Storage CMDlets. I am trying to do some simple automation and wrote a very simple script to initialize, partiion and format a disk

Initialize-disk 1 -PartitionStyle MBR
New-Partition  -diskNumber 1 -DriveLetter L -UseMaximumSize | `
  Format-Volume -FileSystem NTFS -NewFileSystemLabel "Stuff"

When I run this script on a W2012 server it works fine. When I run it from by WinPE disk the Format does not work. No error messages. Nothing. The first 2 statments work but the disk never is formatted and no label is assigned. The same is true with the Clear-Disk Cmdlet. I execute it under W2012 and it works fine. When I execute it under Win-PE it just returns to me and does nothing. I even tried just executing the Format-Volume Cmdlet by itself on WinPE and got the same result -- it immediately came back with no error message and did nothing.

It seems like some cmdlets work and some don't. Anyone have any thoughts?

Thanks

Roger


Roger

$PSCommandPath Stop working.

$
0
0

Is something special why $PSCommandPath not working anymore? It worked ok but it returns null in my script today. Thanks

PS C:\> $PSCommandPath

PS C:\> $PSVersionTable
Name                           Value                                                                           
----                           -----                                                                           
PSVersion                      5.1.17134.228                                                                   
PSEdition                      Desktop                                                                         
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                         
BuildVersion                   10.0.17134.228                                                                  
CLRVersion                     4.0.30319.42000                                                                 
WSManStackVersion              3.0                                                                             
PSRemotingProtocolVersion      2.3                                                                             
SerializationVersion           1.1.0.1                                                                         

Get-ADgroupMember doesn't show the details

$
0
0

Hello, We have multiple domains, I am trying to retrieve the list of domain admins user from each domain with below command.

I am not getting any output, I am missing something in the below script.

$Domain = Get-Content "C:\Temp\Domain.txt"
$DALIST = Get-Content "C:\Temp\DAList.txt"

ForEach-Object ($domains "in" $Domain)
ForEach-Object ($DALISTS 'in' $DALIST)
{
Get-ADGroupmember-server $Domain -Identity $DALIST
}


Thanks HA

powershell learning

$
0
0

Hello everyone,

I am learning windows powershell functions for scripting. I have basic understanding of concepts in powershell but unable to understand functions and how to write code Inside them. Do you know any learning source for powershell functions?

Thank You

How can I use Search-Mailbox to find messages sent from user's primarysmtpaddress?

$
0
0

Over the weekend one of our executives received a scary phishing email with his own email address as the sender. Since it landed in the junk email folder, presumably the phisher just used direct send to deliver it. He asked me to "check everyone's junk email folders to see if they are also receiving phishing emails sent from their own email addresses".

This seems like is should be a pretty straightforward process to feed the PrimarySmtpAddress into -searchquery as 'from: $_.primarysmtpaddress' but I'm not good enough at PowerShell to make this work. Can anyone provide some guidance?

 
Viewing all 21975 articles
Browse latest View live


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