<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PowerShell Archives - HackBuddies</title>
	<atom:link href="https://www.hackbuddies.com/category/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.hackbuddies.com/category/powershell/</link>
	<description>Solutions and optimizations for your daily IT issues and work</description>
	<lastBuildDate>Sat, 17 Oct 2020 13:13:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.hackbuddies.com/wp-content/uploads/2019/07/cropped-apple-icon-152x152-150x150.png</url>
	<title>PowerShell Archives - HackBuddies</title>
	<link>https://www.hackbuddies.com/category/powershell/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Generate ACL Report of File Share with PowerShell to CSV</title>
		<link>https://www.hackbuddies.com/generate-acl-report-of-file-share-with-powershell-to-csv/</link>
					<comments>https://www.hackbuddies.com/generate-acl-report-of-file-share-with-powershell-to-csv/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 12 Jun 2020 09:48:55 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows]]></category>
		<guid isPermaLink="false">https://www.hackbuddies.com/?p=775</guid>

					<description><![CDATA[<p>I think all of you who are administrating file servers, file shares and their permissions, maybe also together with colleagues, will know this situation. Especially at large and complex structures, there are some permissions for users directly granted at the folder and not via the Active Directory / LDAP group. Maybe there are also some [&#8230;]</p>
<p>The post <a href="https://www.hackbuddies.com/generate-acl-report-of-file-share-with-powershell-to-csv/">Generate ACL Report of File Share with PowerShell to CSV</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I think all of you who are administrating file servers, file shares and their permissions, maybe also together with colleagues, will know this situation. Especially at large and complex structures, there are some permissions for users directly granted at the folder and not via the Active Directory / LDAP group. Maybe there are also some wrong AD groups set or inheritance is broken. I want to show you how you can recursively generate an Access Control List Report (NTFS permissions), which is a good basis to clean up your file share permissions. You can Generate ACL Report FileShare with PowerShell.</p>
<p>Basically it is a very simple script, but I will quickly go through it. Of course you need to define the UNC path to the file share or folder. Then you will loop through all the existing directories with a Foreach. At each folder you will get the permissions with <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-acl?view=powershell-7" target="_blank" rel="noopener noreferrer">Get-ACL</a>. Then you need another Foreach to get through all the granted permissions which are inherited or directly set. Then you will add each line to your report and finally export it as a CSV file for further processing. That&#8217;s it!</p>
<pre>$FolderPath = dir -Directory -Path "\\fileserver\fileshare"
$Report = @()
Foreach ($Folder in $FolderPath) {
$Acl = Get-Acl -Path $Folder.FullName
foreach ($Access in $acl.Access)
{
$Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD
Group or
User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Report += New-Object -TypeName PSObject -Property $Properties
}
}
$Report | Export-Csv -path "C:\scripts\FolderPermissions.csv"</pre>
<p>You can extend this script by sending the report as email message directly via PowerShell, <a href="https://www.hackbuddies.com/sending-an-email-within-a-powershell-script/">look here</a>. You can also create a scheduled task / cronjob for this script to Generate ACL Report FileShare periodically.</p>
<p>The post <a href="https://www.hackbuddies.com/generate-acl-report-of-file-share-with-powershell-to-csv/">Generate ACL Report of File Share with PowerShell to CSV</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hackbuddies.com/generate-acl-report-of-file-share-with-powershell-to-csv/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Robocopy: How to Copy Massive Amounts of Data reliably</title>
		<link>https://www.hackbuddies.com/robocopy-how-to-copy-massive-amounts-of-data/</link>
					<comments>https://www.hackbuddies.com/robocopy-how-to-copy-massive-amounts-of-data/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 30 May 2020 08:42:14 +0000</pubDate>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows]]></category>
		<guid isPermaLink="false">https://www.hackbuddies.com/?p=699</guid>

					<description><![CDATA[<p>Introduction Last time I had the task to copy massive amounts of data between two file share systems. With massive amounts I talk about Terabytes 🙂 In addition, one of the systems was productive and the other one the new system, so the solution needed to be reliable and stable. So I asked myself, how [&#8230;]</p>
<p>The post <a href="https://www.hackbuddies.com/robocopy-how-to-copy-massive-amounts-of-data/">Robocopy: How to Copy Massive Amounts of Data reliably</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Last time I had the task to copy massive amounts of data between two file share systems. With massive amounts I talk about Terabytes 🙂 In addition, one of the systems was productive and the other one the new system, so the solution needed to be reliable and stable. So I asked myself, how can I transfer these files and folders? The answer is Robocopy: How to Copy Massive Amounts of Data</p>
<p>So I tried several things and had a look at the possibilites of the systems. I ended up using the simple Robocopy command with the file shares. Of course the client/server executing the Robocopy command had to be in the same local network in order to ensure a good copy speed.</p>
<p>Robocopy offers you the opportunity to define a lot of parameters for your copy job. For example you can define if the Access Control List (NTFS Permissions) should be copied to the destination host, or if you want to create the Access Groups from scratch. Imagine that on the old system there was a lot of direct access set for the users instead of Active Directory groups &#8211; in this case building the Access Groups from scratch can be very helpful to get a clean file share.<br />
Another great thing about Robocopy is that it has basically a Resume option because it copies only the changed or new files after comparing source and destination host.</p>
<h2>The Robocopy Command</h2>
<p>But let&#8217;s talk about the command itself which is pretty simple and you can fulfill nearly all requirements with a One-Liner!</p>
<p>Basically you can split the command as following:</p>
<ul>
<li>Source</li>
<li>Destination</li>
<li>Source Options</li>
<li>Copy Options</li>
</ul>
<p>So let&#8217;s start with the probably most basic command. We want to copy a local directory from one partition to another</p>
<pre>robocopy c:\temp\test d:\temp\</pre>
<p>This simple command will copy the folder test and all files to the location d:\temp &#8211; but not subfolders!</p>
<h3>Copy Everything (including permissions)</h3>
<p>If you simply want to copy everything (also subfolders, empty subfolders, file owners) from the source to destination including the NTFS permission (Windows Access Control list) you can use this command.</p>
<pre>robocopy c:\temp\test d:\temp\ /E /COPYALL</pre>
<h3>Copying over Network</h3>
<p>If you want to use the Robocopy command for copying over the network, like in my case, I recommend you to use the following options and switches to get a good result.</p>
<p>/E -&gt; copy all subfolders, including empty ones.<br />
/V -&gt; produce Verbose output, showing skipped files.<br />
/ZB -&gt; use restartable mode; if access denied use Backup mode.<br />
/R:1 -&gt; number of Retries on failed copies<br />
/W:1 -&gt; Wait time between retries: default is 30 seconds<br />
/NP -&gt; No Progress &#8211; don&#8217;t display percentage copied.<br />
/COPYALL -&gt; COPY ALL file info (equivalent to /COPY: DATSOU)<br />
/LOG -&gt; LOG location</p>
<pre>robocopy \\source_share\folder \\destination_share\folder /E /V /ZB /R:1 /W:1 /NP /COPYALL /LOG:c:\robocopy.log</pre>
<p>So, this ultimative copy job will copy all subfolders, copy all file information, produces verbose output to show skipped files, will retry failed copies and uses the restartable mode with backup mode in case of failed access. In Addition a log file will be generated with all the details of every single file copied. It is simply great! 🙂</p>
<p>Source: <a href="https://community.netapp.com/t5/Data-ONTAP-Discussions/Fileserver-Migration-with-robocopy/td-p/118615" target="_blank" rel="noopener noreferrer">https://community.netapp.com/t5/Data-ONTAP-Discussions/Fileserver-Migration-with-robocopy/td-p/118615</a></p>
<p>Please find the whole documentation of the Robocopy command directly at <a href="https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy" target="_blank" rel="noopener noreferrer">Microsoft Docs</a><br />
Robocopy: How to Copy Massive Amounts of Data</p>
<p>The post <a href="https://www.hackbuddies.com/robocopy-how-to-copy-massive-amounts-of-data/">Robocopy: How to Copy Massive Amounts of Data reliably</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hackbuddies.com/robocopy-how-to-copy-massive-amounts-of-data/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Get Inactive Computers In Active Directory From Specific Organizational Unit With PowerShell</title>
		<link>https://www.hackbuddies.com/get-inactive-computers-in-active-directory-from-specific-organizational-unit-with-powershell/</link>
					<comments>https://www.hackbuddies.com/get-inactive-computers-in-active-directory-from-specific-organizational-unit-with-powershell/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 18 Apr 2020 15:22:55 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">https://www.hackbuddies.com/?p=647</guid>

					<description><![CDATA[<p>From time to time you might want to clean up your Active Directory by moving or removing inactive Computer Objects. But why should you do this? On the one hand, you do not keep unnecessary inactive objects in your Active Directory. On the other hand, you can also save licenses if you also delete these [&#8230;]</p>
<p>The post <a href="https://www.hackbuddies.com/get-inactive-computers-in-active-directory-from-specific-organizational-unit-with-powershell/">Get Inactive Computers In Active Directory From Specific Organizational Unit With PowerShell</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>From time to time you might want to clean up your Active Directory by moving or removing inactive Computer Objects. But why should you do this? On the one hand, you do not keep unnecessary inactive objects in your Active Directory. On the other hand, you can also save licenses if you also delete these inactive computers. Let&#8217;s say you are also using System Center Configuration Manager (SCCM), which can also be cleaned in this action.</p>
<p>This can be fulfilled easily by using a very short but effective PowerShell Inactive Computers script. Simply define the Organizational Unit (OU) you want to use as a SearchBase, specfiy the days of inactivity and that&#8217;s it!<br />
The script will automatically subtract the amount of inactive days from the current date/time and will search the defined OU with the Get-ADComputer command. It will use the attribute <strong>LastLogonTimeStamp</strong> which you can also check in the Attribute Editor of the GUI.</p>
<pre>$TargetOU = "OU=&lt;SubUnit&gt;,OU=&lt;MainUnit&gt;,DC=&lt;domainName&gt;,DC=com"
$DaysInactive = 90
$time = (Get-Date).Adddays(-($DaysInactive))
Get-ADComputer -SearchBase $TargetOU -Filter {LastLogonTimeStamp -lt $time} | Select-Object Name</pre>
<p>Of course you could improve this simple PowerShell Inactive Computers script by adapting the output to a CSV file. Or by selecting more attributes. I would recommend you to create a scheduled task for the script and extend it by <a href="https://www.hackbuddies.com/sending-an-email-within-a-powershell-script/">sending a HTML email/report</a>, so you do not forget to clean up your inactive clients.</p>
<p>You can check out all options of the Get-ADComputer command at <a href="https://docs.microsoft.com/en-us/powershell/module/addsadministration/get-adcomputer?view=win10-ps" target="_blank" rel="noopener noreferrer">Microsoft Docs</a></p>
<p>The post <a href="https://www.hackbuddies.com/get-inactive-computers-in-active-directory-from-specific-organizational-unit-with-powershell/">Get Inactive Computers In Active Directory From Specific Organizational Unit With PowerShell</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hackbuddies.com/get-inactive-computers-in-active-directory-from-specific-organizational-unit-with-powershell/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SharePoint Online Management Shell: Restore A Deleted Site or OneDrive storage</title>
		<link>https://www.hackbuddies.com/sharepoint-online-management-shell-restore-a-deleted-site/</link>
					<comments>https://www.hackbuddies.com/sharepoint-online-management-shell-restore-a-deleted-site/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 28 Mar 2020 17:06:39 +0000</pubDate>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SaaS]]></category>
		<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">https://www.hackbuddies.com/?p=626</guid>

					<description><![CDATA[<p>If you are also using SharePoint or OneDrive Online &#8211; welcome! It is a great Software as a Service (SaaS) cloud tool from Microsoft and I really love it. Unfortunately I had the following case last time: A SharePoint site which was linked to an Office 365 group was accidentally deleted and I was not [&#8230;]</p>
<p>The post <a href="https://www.hackbuddies.com/sharepoint-online-management-shell-restore-a-deleted-site/">SharePoint Online Management Shell: Restore A Deleted Site or OneDrive storage</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you are also using SharePoint or OneDrive Online &#8211; welcome! It is a great Software as a Service (SaaS) cloud tool from Microsoft and I really love it. Unfortunately I had the following case last time:<br />
A SharePoint site which was linked to an Office 365 group was accidentally deleted and I was not able to restore it via Microsoft 365 (M365) Admin Center, because it happened more than 30 days ago.<br />
In general, all resources of the O365 group are deleted after a period of 30 days. But not the SharePoint site! It will be retained for 93 days &#8211; That&#8217;s great.<br />
Keep in mind that this can also happen with OneDrive storages of users. After 30 days they are basically gone, but can still be restored with SharePoint Online Management Shell. SharePoint Online Restore Site</p>
<p>At first, you have to establish a connection to SharePoint Online with PowerShell. Let&#8217;s check if the module is already installed:</p>
<pre class="has-inner-focus" tabindex="0"><code class="lang-ps" data-author-content="Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version "><span class="hljs-pscommand">Get-Module</span><span class="hljs-parameter"> -Name</span> Microsoft.Online.SharePoint.PowerShell<span class="hljs-parameter"> -ListAvailable</span> | Select Name,Version
</code></pre>
<p>If not, simply install it:</p>
<pre class="has-inner-focus" tabindex="0"><code class="lang-ps" data-author-content="Install-Module -Name Microsoft.Online.SharePoint.PowerShell "><span class="hljs-pscommand">Install-Module</span><span class="hljs-parameter"> -Name</span> Microsoft.Online.SharePoint.PowerShell</code></pre>
<p>Now we can set up the connection. If you have Multi Factor Authentication (MFA) enabled, you cannot pass the credentials with the Get-Credentials command. But you can use this snippet:</p>
<pre>$orgName="&lt;Insert your Org name here&gt;" 
Connect-SPOService -Url https://$orgName-admin.sharepoint.com</pre>
<p>A window will pop-up prompting you for the MFA code from Microsoft Authenticator or the text message. After authentication is done &#8211; we are nearly finished.<br />
Check the Deleted Sites for your site name and store it directly in a variable:</p>
<pre><span class="hljs-variable">$deletedSite</span> = <span class="hljs-pscommand">Get-SPDeletedSite</span> /sites/site_name</pre>
<p>At last restore the deleted site:</p>
<p class="has-inner-focus" tabindex="0"><code class="lang-powershell" data-author-content="$deletedSite = Get-SPDeletedSite /sites/site_name Restore-SPDeletedSite -Identity $deletedSite"><span class="hljs-pscommand">Restore-SPDeletedSite</span><span class="hljs-parameter"> -Identity</span> <span class="hljs-variable">$deletedSite</span></code></p>
<p tabindex="0">If you want to check out more about the possibilites and the SharePoint PowerShell, I recommend you to check <a href="https://docs.microsoft.com/en-us/powershell/sharepoint/?view=sharepoint-ps" target="_blank" rel="noopener noreferrer">Microsoft Docs.</a><br />
If you are new to PowerShell, check out my <a href="https://www.hackbuddies.com/category/powershell/">other articles</a><br />
SharePoint Online Restore Site</p>
<p>The post <a href="https://www.hackbuddies.com/sharepoint-online-management-shell-restore-a-deleted-site/">SharePoint Online Management Shell: Restore A Deleted Site or OneDrive storage</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hackbuddies.com/sharepoint-online-management-shell-restore-a-deleted-site/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Export Active Directory Groups and their Members from a specific Organizational Unit as CSV with PowerShell</title>
		<link>https://www.hackbuddies.com/export-active-directory-groups-and-their-members-from-a-specific-organizational-unit-as-csv-with-powershell/</link>
					<comments>https://www.hackbuddies.com/export-active-directory-groups-and-their-members-from-a-specific-organizational-unit-as-csv-with-powershell/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 16 Feb 2020 10:40:31 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">https://www.hackbuddies.com/?p=620</guid>

					<description><![CDATA[<p>I wanted to share a simple but effective PowerShell script with you. It is especially useful, if there are a lot of groups distributed in different Organizational Units. They may manage the access to file shares on your file servers and you used only Global Security groups in Active Directory for this purpose. So, we [&#8230;]</p>
<p>The post <a href="https://www.hackbuddies.com/export-active-directory-groups-and-their-members-from-a-specific-organizational-unit-as-csv-with-powershell/">Export Active Directory Groups and their Members from a specific Organizational Unit as CSV with PowerShell</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I wanted to share a simple but effective PowerShell script with you. It is especially useful, if there are a lot of groups distributed in different Organizational Units. They may manage the access to file shares on your file servers and you used only Global Security groups in Active Directory for this purpose. So, we want to export all these Global Security groups in the specific OU, but also all of their members to create a huge table or matrix. You can send this table afterwards to the corresponding manager for example, so he can review the currently set permissions to the file shares.</p>
<p>Feel free to adapt the script or write some interesting ideas how to extend it in the comments 🙂</p>
<pre># Define date, output file and OU
$DateTime = Get-Date -f "yyyy-MM-dd_hh-mm" 
$OutputFile = "C:\scripts\" + $DateTime + "-ADGroupsAndMembers.csv"
$TargetOU = "OU=&lt;SubUnit&gt;,OU=&lt;MainUnit&gt;,DC=&lt;domainName&gt;,DC=com"

# Check OU and set filter for Global Security Groups
$Groups = Get-ADGroup -SearchBase $TargetOU -filter {GroupCategory -eq "Security" -and GroupScope -ne "DomainLocal"}

$Table = @()

$Record = @{
"Group Name" = ""
"Name" = ""
"Username" = ""
}

Foreach ($Group in $Groups) {
    $Arrayofmembers = Get-ADGroupMember -identity $Group -recursive | Select-Object name,samaccountname
        foreach ($Member in $Arrayofmembers) {
            $Record."Group Name" = $Group
            $Record."Name" = $Member.name
            $Record."UserName" = $Member.samaccountname
            $objRecord = New-Object PSObject -property $Record
            $Table += $objrecord
     }
}

$Table | Sort-Object Name | Export-Csv $OutputFile -NoTypeInformation -Encoding UTF8</pre>
<p>The post <a href="https://www.hackbuddies.com/export-active-directory-groups-and-their-members-from-a-specific-organizational-unit-as-csv-with-powershell/">Export Active Directory Groups and their Members from a specific Organizational Unit as CSV with PowerShell</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hackbuddies.com/export-active-directory-groups-and-their-members-from-a-specific-organizational-unit-as-csv-with-powershell/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Windows PowerShell: Generate Battery Report</title>
		<link>https://www.hackbuddies.com/windows-powershell-generate-battery-report/</link>
					<comments>https://www.hackbuddies.com/windows-powershell-generate-battery-report/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 22 Dec 2019 13:21:45 +0000</pubDate>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows]]></category>
		<guid isPermaLink="false">https://www.hackbuddies.com/?p=580</guid>

					<description><![CDATA[<p>Lately I created an advertisement to sell my old laptop via an online portal/marketplace. One potential buyer asked me, how the condition of the battery is. So I asked myself &#8211; how could I answer that in good way, if there is no battery test available in BIOS? I did some research and found out [&#8230;]</p>
<p>The post <a href="https://www.hackbuddies.com/windows-powershell-generate-battery-report/">Windows PowerShell: Generate Battery Report</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Lately I created an advertisement to sell my old laptop via an online portal/marketplace. One potential buyer asked me, how the condition of the battery is. So I asked myself &#8211; how could I answer that in good way, if there is no battery test available in BIOS? I did some research and found out that it is pretty easy to check the battery state with PowerShell. With one simple command, you can generate a battery report which outputs very useful data. I will let you know how to do that with Windows PowerShell Battery Report</p>
<h2>Start PowerShell as administrator</h2>
<p>1.) Start PowerShell as admin by right-clicking at the Windows Start button and selecting it:</p>
<p><a href="https://www.hackbuddies.com/wp-content/uploads/2019/12/AccessPowerShell.png"><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-598" src="https://www.hackbuddies.com/wp-content/uploads/2019/12/AccessPowerShell.png" alt="" width="263" height="566" srcset="https://www.hackbuddies.com/wp-content/uploads/2019/12/AccessPowerShell.png 263w, https://www.hackbuddies.com/wp-content/uploads/2019/12/AccessPowerShell-139x300.png 139w, https://www.hackbuddies.com/wp-content/uploads/2019/12/AccessPowerShell-195x420.png 195w" sizes="(max-width: 263px) 100vw, 263px" /></a></p>
<h2>Create Battery Report</h2>
<p>2.) Now, simply copy &amp; paste the following command:<br />
<b>powercfg /batteryreport /output &#8220;C:\battery-report.html&#8221;<br />
</b>After executing it, the report will be saved to the defined directory, in this case directly to the C:\ partition<br />
<a href="https://www.hackbuddies.com/wp-content/uploads/2019/12/PowerShellBatteryReport.png"><img decoding="async" class="alignnone size-full wp-image-602" src="https://www.hackbuddies.com/wp-content/uploads/2019/12/PowerShellBatteryReport.png" alt="" width="569" height="47" srcset="https://www.hackbuddies.com/wp-content/uploads/2019/12/PowerShellBatteryReport.png 569w, https://www.hackbuddies.com/wp-content/uploads/2019/12/PowerShellBatteryReport-300x25.png 300w" sizes="(max-width: 569px) 100vw, 569px" /></a></p>
<p>Of course you can check out the whole documentation of the powercfg command at <a href="https://docs.microsoft.com/en-us/windows-hardware/design/device-experiences/powercfg-command-line-options" target="_blank" rel="noopener noreferrer">Microsoft Docs</a></p>
<h2>Check HTML Report</h2>
<p>3.) Open up your Windows File Explorer and navigate to the defined directory. Here you will find the .HTML file which can be opened with your favourite browser:<br />
<a href="https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryReportFile.png"><img decoding="async" class="alignnone size-full wp-image-600" src="https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryReportFile.png" alt="" width="765" height="301" srcset="https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryReportFile.png 765w, https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryReportFile-300x118.png 300w, https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryReportFile-696x274.png 696w" sizes="(max-width: 765px) 100vw, 765px" /></a></p>
<h2>Windows PowerShell Battery Report</h2>
<p>Just have a look through the whole Windows PowerShell Battery Report, it is quite interesting and you are able to gain some insights. My new laptop e.g. has a battery cycle count of 23 and the full charge capacity is nearly as good as the design capacity:<br />
<a href="https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryCycleCount.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-599" src="https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryCycleCount.png" alt="" width="384" height="315" srcset="https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryCycleCount.png 384w, https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryCycleCount-300x246.png 300w" sizes="auto, (max-width: 384px) 100vw, 384px" /></a></p>
<p>Of course you can also check the details of your battery usage with the active time of the sessions and the effective battery drain:<br />
<a href="https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryUsage.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-601" src="https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryUsage.png" alt="" width="917" height="775" srcset="https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryUsage.png 917w, https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryUsage-300x254.png 300w, https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryUsage-768x649.png 768w, https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryUsage-696x588.png 696w, https://www.hackbuddies.com/wp-content/uploads/2019/12/BatteryUsage-497x420.png 497w" sizes="auto, (max-width: 917px) 100vw, 917px" /></a></p>
<p>The post <a href="https://www.hackbuddies.com/windows-powershell-generate-battery-report/">Windows PowerShell: Generate Battery Report</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hackbuddies.com/windows-powershell-generate-battery-report/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Move Computers From .TXT File To Different OU In Active Directory With PowerShell</title>
		<link>https://www.hackbuddies.com/move-computer-accounts-from-txt-file-to-different-ou-in-active-directory-with-powershell/</link>
					<comments>https://www.hackbuddies.com/move-computer-accounts-from-txt-file-to-different-ou-in-active-directory-with-powershell/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 12 Sep 2019 07:50:57 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">https://www.hackbuddies.com/?p=466</guid>

					<description><![CDATA[<p>Imagine the following situation: You want to bulk move Computers to different OU. You already use a tool to check your Active Directory for inactive devices (e.g. Last Logon Date 100 days before). This tool offers the possibility to export these old computers to a .TXT file. Before deleting them completely, you may want to [&#8230;]</p>
<p>The post <a href="https://www.hackbuddies.com/move-computer-accounts-from-txt-file-to-different-ou-in-active-directory-with-powershell/">Move Computers From .TXT File To Different OU In Active Directory With PowerShell</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="td-paragraph-padding-1">

Imagine the following situation: You want to bulk move Computers to different OU.
You already use a tool to check your Active Directory for inactive devices (e.g. Last Logon Date 100 days before). This tool offers the possibility to export these old computers to a .TXT file. Before deleting them completely, you may want to move them to a different Organizational Unit (OU) to keep them for a few more days. Instead of moving them manually, use this simple PowerShell script which accepts a .TXT file as input, reads the computer names line by line and loops through them.
<pre># Specify path to the text file with the computer account names.
$computers = Get-Content \\PathToScript\ComputersToDelete.txt

# Specify path to the OU where computers will be moved.
$TargetOU = "OU=Users,OU=&lt;SubUnit&gt;,OU=&lt;MainUnit&gt;,DC=&lt;domainName&gt;,DC=com"

# Move Computers to the new OU
ForEach($computer in $computers){
    Get-ADComputer $computer | Move-ADObject -TargetPath $TargetOU
}</pre>
</div>
Of course you could combine that with the following script: <a href="https://www.hackbuddies.com/get-inactive-computers-in-active-directory-from-specific-organizational-unit-with-powershell/">Get Inactive Computers</a>

If you are interested in the full possibilites of Get-ADComputer, you can check <a href="https://docs.microsoft.com/en-us/powershell/module/addsadministration/get-adcomputer?view=win10-ps" target="_blank" rel="noopener noreferrer">Microsoft Docs </a>to Move Computers to different OU

<!-- /wp:post-content --><p>The post <a href="https://www.hackbuddies.com/move-computer-accounts-from-txt-file-to-different-ou-in-active-directory-with-powershell/">Move Computers From .TXT File To Different OU In Active Directory With PowerShell</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hackbuddies.com/move-computer-accounts-from-txt-file-to-different-ou-in-active-directory-with-powershell/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Sending HTML Email with AD User Groups</title>
		<link>https://www.hackbuddies.com/sending-html-email-with-ad-user-groups/</link>
					<comments>https://www.hackbuddies.com/sending-html-email-with-ad-user-groups/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 22 Jul 2019 05:08:32 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">https://www.hackbuddies.com/?p=293</guid>

					<description><![CDATA[<p>An inquiry, which occurs very often in daily business: &#8220;What permissions does a specific user have?&#8221; What about sending a HTML Email with AD User Groups to the requestor?In most cases the Active Directory groups represent file access, system access and many more. So, exporting these groups would be a good way. Due to the [&#8230;]</p>
<p>The post <a href="https://www.hackbuddies.com/sending-html-email-with-ad-user-groups/">Sending HTML Email with AD User Groups</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="td-paragraph-padding-1">
<p>An inquiry, which occurs very often in daily business: &#8220;What permissions does a specific user have?&#8221; What about sending a HTML Email with AD User Groups to the requestor?<br />In most cases the Active Directory groups represent file access, system access and many more. So, exporting these groups would be a good way. Due to the fact that I did not want to start up my PowerShell for a CSV export which is then manually sent to the user every time, the following idea came up:</p>
<p>What about writing a PowerShell script, which just asks for the username and the email address of the superior who wants to see and check the permissions? After feeding the script with these two inputs, the Active Directory groups are queried and automatically sent to the superior in a HTML-formatted email. Very simple and time-saving!<br />After that I had the idea to extend the script with the &#8220;Description&#8221; field of the Active Directory groups. Thus, not just the group name but also the corresponding description gets exported and sent.</p>
<h2>PowerShell Script</h2>
<pre>$UserName = (Read-Host "Username")<br />$EmailSuperior = (Read-Host "Email address of superior")<br /><br />$style = "&lt;style&gt;BODY{font-family: Arial; font-size: 10pt;}"<br />$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"<br />$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"<br />$style = $style + "TD{border: 1px solid black; padding: 5px; }"<br />$style = $style + "&lt;/style&gt;"<br /><br /># Get group memberships from reference user, sort them alphabetically and export to TXT file<br /># Define parameters for mailing and send mail to IT-responsible person to review permissions<br />$Permissions = Get-ADPrincipalGroupMembership -Identity $UserName| Get-ADGroup -Properties * | Select name, description | Sort-Object -Property name | ConvertTo-Html -Head $style<br />$SmtpServer = 'smtp.yourdomain.com'<br />$SmtpPort = 587<br />$FromSender = 'admin@yourdomain.com'<br />$Subject = 'User permission check: ' + $UserName<br /><br /># Email Body Set Here, Note You can use HTML, including Images.<br />$Body ="<br />Hello,&lt;br&gt;<br />&lt;br&gt;<br />The permissions of user &lt;B&gt;$UserName&lt;/B&gt; are set as below. Please check and review them.&lt;br&gt;<br />&lt;hr&gt;<br />&lt;br&gt;<br />&lt;B&gt;Permissions:&lt;/B&gt;&lt;br&gt;<br />$Permissions<br />&lt;br&gt;<br />"<br /><br />Send-MailMessage -SmtpServer $SmtpServer -Port $SmtpPort -From $FromSender -To $EmailSuperior -Bcc $FromSender -Subject $Subject -Encoding "UTF8" -Body $Body -BodyAsHtml</pre>
<p>This script will generate the following email message. Please note that I removed the original permissions and username and replaced it with placeholders 🙂</p>
<p>So that&#8217;s how you are sending HTML Email with AD User Groups. Please check up details regarding the Send-MailMessage command directly at <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-7" target="_blank" rel="noopener noreferrer">Microsoft Docs</a></p>
<p>Let me know your thoughts in the comment section. Of course you can use this HTML email part in other scripts too, for example to send inactive computer list to the responsible person like <a href="https://www.hackbuddies.com/get-inactive-computers-in-active-directory-from-specific-organizational-unit-with-powershell/">here</a></p>
<h2>Output of the Script</h2>
<hr />
<p><em>Hello,</em></p>
<p><em>The permissions of user <strong>&lt;USERNAME&gt;</strong> are set as below. Please check and review them.<br /></em></p>
<p><em><strong>Permissions:</strong></em></p>
<table>
<tbody>
<tr>
<td>
<p><em><strong>name</strong></em></p>
</td>
<td>
<p><em><strong>description</strong></em></p>
</td>
</tr>
<tr>
<td>
<p><em>Permission1</em></p>
</td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td>
<p><em>Permission2</em></p>
</td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td>
<p><em>Permission3</em></p>
</td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td>
<p><em>Permission4</em></p>
</td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td>
<p><em>Permission5</em></p>
</td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td><em>Permission6</em></td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td><em>Permission7</em></td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td><em>Permission8</em></td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td><em>Permission9</em></td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td><em>Permission10</em></td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td><em>Permission</em></td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td><em>Permission</em></td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
<tr>
<td><em>Permission</em></td>
<td>
<p><em>Description from AD here</em></p>
</td>
</tr>
</tbody>
</table>
</div>

<p>&nbsp;</p>
<p>The post <a href="https://www.hackbuddies.com/sending-html-email-with-ad-user-groups/">Sending HTML Email with AD User Groups</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hackbuddies.com/sending-html-email-with-ad-user-groups/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Sending an email within a PowerShell script</title>
		<link>https://www.hackbuddies.com/sending-an-email-within-a-powershell-script/</link>
					<comments>https://www.hackbuddies.com/sending-an-email-within-a-powershell-script/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 14 Jun 2019 17:10:20 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">https://www.hackbuddies.com/?p=276</guid>

					<description><![CDATA[<p>Imagine you need to inform an user about something which had already been automated in a PowerShell script. You do not want to start a manual task (e.g. sending an email) every time the script is executed. Especially if you need it multiple times per day. So I decided to extend the script with the [&#8230;]</p>
<p>The post <a href="https://www.hackbuddies.com/sending-an-email-within-a-powershell-script/">Sending an email within a PowerShell script</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="td-paragraph-padding-1">
<p>Imagine you need to inform an user about something which had already been automated in a PowerShell script. You do not want to start a manual task (e.g. sending an email) every time the script is executed. Especially if you need it multiple times per day. So I decided to extend the script with the email-sending function. Just a few lines of code are necessary and you can adapt it to your needs. Mail Subject and Mail Body can be modified and even attachments can be added. Sending Email with PowerShell</p>
<p>To show you the possibilities, the following script reads the assigned groups of an Active Directory user and exports them to a .txt file. Then, the email data gets specified and afterwards the email will be sent to the recipient.</p>
<pre>$Permissions = Get-ADPrincipalGroupMembership -Identity $Username | Select name | Sort-Object name | Out-File -FilePath C:\temp\AssignedGroups.txt<br />$SmtpServer = 'myServer.myDomain.com'<br />$SmtpPort = 587<br />$FromSender = 'mySender@myDomain.com'<br />$Recipient = 'myRecipient@myDomain.com'<br />$Subject = 'Assigned groups from : ' + $UserName<br />$PermissionsFilePath = "C:\temp\AssignedGroups.txt"<br />$Body = Get-Content -Path $PermissionsFilePath | Out-String <br />Send-MailMessage -SmtpServer $SmtpServer -Port $SmtpPort -From $FromSender -To $Recipient -Subject $Subject -Body $Body -Attachments $PermissionsFilePath</pre>
</div>

<p>I would definitely recommend you to check out the <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-7" target="_blank" rel="noopener noreferrer">Microsoft Docs</a> about the Send-MailMessage command in order to properly adapt it to your needs and requirements. You can also combine that script with other ones. For example, you can <a href="https://www.hackbuddies.com/export-active-directory-groups-and-their-members-from-a-specific-organizational-unit-as-csv-with-powershell/">export Active Directory Groups and their members from a specific organizational unit as CSV</a> and send an automated email message within a scheduled task &#8211; there are no limitations.<br />Sending Email with PowerShell</p>
<p>The post <a href="https://www.hackbuddies.com/sending-an-email-within-a-powershell-script/">Sending an email within a PowerShell script</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hackbuddies.com/sending-an-email-within-a-powershell-script/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Export user data from Active Directory</title>
		<link>https://www.hackbuddies.com/export-user-data-from-active-directory/</link>
					<comments>https://www.hackbuddies.com/export-user-data-from-active-directory/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 31 May 2019 12:47:24 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">https://www.hackbuddies.com/?p=227</guid>

					<description><![CDATA[<p>It will happen again and again. Your customers or colleagues will ask you to export specific user data from Active Directory. The easiest way to do this is with the command &#8220;Get-ADUser&#8221;. Simply select the specific objects like DisplayName, Username,.. and export the result to a CSV file with the specified encoding and delimiter. Import-Module [&#8230;]</p>
<p>The post <a href="https://www.hackbuddies.com/export-user-data-from-active-directory/">Export user data from Active Directory</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="td-paragraph-padding-1">
<p>It will happen again and again. Your customers or colleagues will ask you to export specific user data from Active Directory. The easiest way to do this is with the command &#8220;Get-ADUser&#8221;. Simply select the specific objects like DisplayName, Username,.. and export the result to a CSV file with the specified encoding and delimiter.</p>
<pre>Import-Module ActiveDirectory<br>Get-ADUser -Filter * -properties * | select-object DisplayName,sAMAccountName,telephoneNumber,mobile,mail,Department,Description | export-csv c:\temp\UserDataExport.csv -Encoding utf8 -notype -Delimiter ";"</pre>
<p>Most of the time not all users are necessary, so there are more options to filter of course.</p>
<h2>Export only specific Organizational Unit (OU)</h2>
<p>You can filter for an Organizational Unit by using the -SearchBase option:</p>
<pre>Import-Module ActiveDirectory<br>Get-ADUser -SearchBase "OU=Users,OU=&lt;SubUnit&gt;,OU=&lt;MainUnit&gt;,DC=&lt;domainName&gt;,DC=com" -Filter * -properties * | select-object DisplayName,sAMAccountName,telephoneNumber,mobile,mail,Department,Description | export-csv c:\temp\UserDataExport.csv -Encoding utf8 -notype -Delimiter ";"</pre>
<h2>Export group members</h2>
<p>Another useful command is to export the members of a security group:</p>
<pre>Import-Module ActiveDirectory<br>Get-ADGroupMember -Identity '&lt;GroupName&gt;' | Select-Object name, samaccountname | export-csv c:\temp\exportGroupMembers.csv -Encoding utf8 -NoType -Delimiter ";"</pre>
</div>


<p></p>
<p>The post <a href="https://www.hackbuddies.com/export-user-data-from-active-directory/">Export user data from Active Directory</a> appeared first on <a href="https://www.hackbuddies.com">HackBuddies</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hackbuddies.com/export-user-data-from-active-directory/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
